0

我尝试在测试场景中使用 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));
                }
            });
4

1 回答 1

2

如果您只希望它运行一次,则设置trigger.repeatCount=0

于 2012-06-11T03:44:28.540 回答