简体   繁体   English

Apache Camel不发送传入消息的回复

[英]Apache Camel not sending reply for incoming message

I have Camel route which listens for incoming JMS messages. 我有侦听传入JMS消息的骆驼路线。 For some reason, the route doesn't send response to the JMS replyTo address. 由于某种原因,路由不会将响应发送到JMS ReplyTo地址。 In the following example, the program hangs waiting for the reply message to be arrived at temporary destination. 在下面的示例中,程序挂起,等待回复消息到达临时目标。 How do I make the JMS-listening route to handle the messages InOut-fashion? 如何制作JMS侦听路由以处理InOut-fashion消息?

@Component("testRouteBuilder")
public class TestRouteBuilder extends RouteBuilder {

    @SuppressWarnings("unchecked")
    @Override
    public void configure() throws Exception {

        from("timer://foo?delay=2000")
            .setBody(simple("hello"))
            .log("request: ${body}")
            .to("bean://jmsbean")
            .log("reply: ${body}");

        from("jms://queue:dest")
//          .setExchangePattern(ExchangePattern.InOut) // Not working
            .log("got message")
            .log("${headers}")
            .setBody(constant("reply"));
    }

    @Component("jmsbean")
    public static class JmsBean {

        @Autowired
        ConnectionFactory jmsServer1;

        @Autowired
        ConnectionFactory jmsServer2;

        public String testJms(@Body String body) throws JMSException {

            Connection conn = jmsServer1.createConnection();
            conn.start();
            Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

            Connection conn2 = jmsServer2.createConnection();
            conn2.start();
            Session session2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);

            TemporaryQueue tempQueue = session2.createTemporaryQueue();

            TextMessage message = session.createTextMessage();
            message.setJMSCorrelationID("tuomas");
            message.setJMSReplyTo(tempQueue);
            message.setJMSMessageID("tuomas");

            Queue dest = session.createQueue("dest");
            MessageProducer producer = session.createProducer(dest);
            producer.send(message);

            session.close();
            conn.close();

            MessageConsumer consumer = session2.createConsumer(tempQueue, "tuomas");
            Message reply = consumer.receive();

            session2.close();
            conn2.close();

            return reply.getBody(String.class);
        }
    }
}

.

2018-04-06 18:24:31.497  INFO 15256 --- [           main] t.springcamel.SpringcamelApplication     : Started SpringcamelApplication in 6.143 seconds (JVM running for 11.263)
2018-04-06 18:24:33.456  INFO 15256 --- [2 - timer://foo] route1                                   : request: hello
2018-04-06 18:24:33.503  INFO 15256 --- [sConsumer[dest]] route2                                   : got message
2018-04-06 18:24:33.503  INFO 15256 --- [sConsumer[dest]] route2                                   : {breadcrumbId=ID-DESKTOP-LI5P50P-1523028268251-0-2, JMSCorrelationID=tuomas, JMSCorrelationIDAsBytes=tuomas, JMSDeliveryMode=2, JMSDestination=queue://dest, JMSExpiration=0, JMSMessageID=ID:DESKTOP-LI5P50P-51501-1523028271227-4:2:1:1:1, JMSPriority=4, JMSRedelivered=false, JMSReplyTo=temp-queue://ID:DESKTOP-LI5P50P-51501-1523028271227-4:3:1, JMSTimestamp=1523028273488, JMSType=null, JMSXGroupID=null, JMSXUserID=null}

AFAIK, Camel by default sends a message to replyTo queue. AFAIK,默认情况下,骆驼发送消息到replyTo队列。 It is stated so in JMS component docs within an attribute disableReplyTo . JMS组件文档中,属性disableReplyTo对此进行了说明。 I have experienced such behaviour by myself. 我自己经历了这种行为。

However, your message is not consumed by any consumer in your example. 但是,您的示例中的任何使用者都不会使用您的消息。 For example, you can try to send it to some bean. 例如,您可以尝试将其发送到某个bean。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM