使用AsyncProcessor时还会有另外一条消息

时间:2012-06-08 11:48:01

标签: apache-camel

我尝试在测试场景中使用AsyncProcessor,期望只有一条消息通过路由运行,但似乎有两条消息。

在日志中

Test0
Test1

为什么有两条消息?

from("quartz:test?trigger.repeatCount=1&trigger.repeatInterval=100").setBody(simple("Test"))

            .process(new AsyncProcessor() {

                private volatile int i;

                public void process(Exchange exchange) throws Exception {
                    AsyncProcessorHelper.process(this, exchange);
                }

                public boolean process(final Exchange exchange, final AsyncCallback callback) {
                    new Thread(new Runnable() {

                        public void run() {
                            exchange.getOut().setBody(exchange.getIn().getBody(String.class) + (i++), String.class);
                            callback.done(false);
                        }
                    }).start();
                    return false;
                }
            })
                .process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    org.slf4j.LoggerFactory.getLogger(Tests.class).info(exchange.getIn().getBody(String.class));
                }
            });

1 个答案:

答案 0 :(得分:2)

如果您只想运行一次,请设置trigger.repeatCount=0