通过使用者模板进行聚合和过滤

时间:2016-02-10 21:50:37

标签: apache-camel aggregate consumer

这是一般性的,最佳实践问题是什么......

我有一些进程,其中使用了使用者模板来读取目录(或MQ队列)以查找可用的任何内容然后自行停止,它调用的整个路由集是基于一些参数以编程方式创建的< / p>

所以使用下面的消费者模板方法......有没有办法分配

  • 以编程方式进行过滤操作(即,如果我想从下面过滤掉某些文件,如果它通过标准路线很容易...(通过.filter)但此刻,我没有预定义bean,所以在EIP中添加#filter = filter实际上不是一个选项。

  • 我的while循环内部的聚合函数。 (虽然仍在使用模板)。

    @Override
    public void process(Exchange exchange) throws Exception {
    
        getConsumer().start();                      
        int exchangeCount = 0;
        while (true) {
            String consumerEp = "file:d://directory?delete=true&sendEmptyMessageWhenIdle=true&idempotent=false";
            Exchange fileExchange = getConsumer().receive(consumerEp);
            if (fileExchange == null || fileExchange.getIn()==null || fileExchange.getIn().getHeader(CAMEL_FILE_NAME)==null) {
                break;
            }
            exchangeCount++;
            Boolean batchStatus = (Boolean) fileExchange.getProperty(PROP_CAMEL_BATCH_COMPLETE);
            LOG.info("---PROCESSING : " + fileExchange.getIn().getHeader(CAMEL_FILE_NAME));
            getProducer().send("direct:some-other-process", fileExchange);
    
            //Get the CamelBatchComplete Property to establish the end of the batch, and not cycle through twice.
            if(batchStatus!=null && batchStatus==true){
                break;                      
            }                   
        }       
        // Stop the consumer service
        getConsumer().stop();
        LOG.info("End Group Operation : Total Exchanges=" + exchangeCount);
    }
    

0 个答案:

没有答案