2

我对 Camel 和 JMS 有疑问。

我的路线很简单:

  @Override
    protected RouteBuilder[] createRouteBuilders() throws Exception {
        createJmsComponent();

        RouteBuilder route1 = new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:startpoint")
                .log("TO JMS: ${body}")
                .to("jms://queue:QUEUE.NAME.OUT?replyTo=QUEUE.NAME.IN&replyToType=Exclusive")
                ;
            }
        };

        RouteBuilder route2 = new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("jms://queue:QUEUE.NAME.IN?receiveTimeout=10000")
                .log("FROM JMS: ${body}")
                ;
            }
        };
        return new RouteBuilder[]{route1, route2};
    }

在日志中我有我需要的东西:

2012-07-04 16:28:10,443 INFO  route1 - TO JMS: message
2012-07-04 16:28:13,477 INFO  route2 - FROM JMS: message

但问题是我有异常:

2012-07-04 16:28:33,960 ERROR o.a.c.p.DefaultErrorHandler                        - Failed delivery for (MessageId: ID-PLWROW912268-4634-1341412084839-0-1 on ExchangeId: ID-PLWROW912268-4634-1341412084839-0-2). Exhausted after delivery attempt: 1 caught: org.apache.camel.ExchangeTimedOutException: The OUT message was not received within: 20000 millis due reply message with correlationID: ID-PLWROW912268-4634-1341412084839-0-3 not received. Exchange[Message: message]
org.apache.camel.ExchangeTimedOutException: The OUT message was not received within: 20000 millis due reply message with correlationID: ID-PLWROW912268-4634-1341412084839-0-3 not received. Exchange[Message: message]
    at org.apache.camel.component.jms.reply.ReplyManagerSupport.processReply(ReplyManagerSupport.java:126) ~[camel-jms-2.9.2.jar:2.9.2]
    at org.apache.camel.component.jms.reply.TemporaryQueueReplyHandler.onTimeout(TemporaryQueueReplyHandler.java:61) [camel-jms-2.9.2.jar:2.9.2]
    at org.apache.camel.component.jms.reply.CorrelationTimeoutMap.onEviction(CorrelationTimeoutMap.java:53) [camel-jms-2.9.2.jar:2.9.2]
    at org.apache.camel.component.jms.reply.CorrelationTimeoutMap.onEviction(CorrelationTimeoutMap.java:30) [camel-jms-2.9.2.jar:2.9.2]
    at org.apache.camel.support.DefaultTimeoutMap.purge(DefaultTimeoutMap.java:203) [camel-core-2.9.2.jar:2.9.2]
    at org.apache.camel.support.DefaultTimeoutMap.run(DefaultTimeoutMap.java:159) [camel-core-2.9.2.jar:2.9.2]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) [na:1.6.0_23]
    at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317) [na:1.6.0_23]
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150) [na:1.6.0_23]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98) [na:1.6.0_23]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180) [na:1.6.0_23]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204) [na:1.6.0_23]
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [na:1.6.0_23]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [na:1.6.0_23]
    at java.lang.Thread.run(Thread.java:662) [na:1.6.0_23]

如果我理解正确,现在我有两条等待响应的路线。Route2 从 Queue 读取响应,route1 没有得到响应(因为被 route2 读取),这就是我得到异常的原因。

所以我需要做些什么来得到这个场景:

route1 - only send message to JMS and not waiting for response. 
route2 - only read message from JMS.
4

2 回答 2

5

解决方案是使用 inOnly 模式和 preserveMessageQos=true 标志。

.inOnly("jms://queue:QUEUE.NAME.OUT" +
                            "?replyTo=QUEUE.NAME.IN" +
                            "&replyToType=Shared" +
                            "&preserveMessageQos=true")
于 2012-07-05T08:09:01.057 回答
0

如果您只想让 route1 将消息发送到 route2 正在侦听的队列,则不要使用 replyTo 或单独的队列......只需这样做。

from("direct:startpoint").log("TO JMS: ${body}").to("jms://queue:QUEUE.NAME.IN");

from("jms://queue:QUEUE.NAME.IN").log("FROM JMS: ${body}");
于 2012-07-05T04:58:38.760 回答