178.18. 늦은 응답에 JMSReplyTo 사용

Camel을 JMS 리스너로 사용할 때 ReplyTo javax.jms.Destination 오브젝트의 값으로 Exchange 속성을 설정합니다. ReplyTo. 다음과 같이 이 목적지 를 얻을 수 있습니다.

Destination replyDestination = exchange.getIn().getHeader(JmsConstants.JMS_REPLY_DESTINATION, Destination.class);

나중에 일반 JMS 또는 Camel을 사용하여 응답을 전송하는 데 사용합니다.

// we need to pass in the JMS component, and in this sample we use ActiveMQ
JmsEndpoint endpoint = JmsEndpoint.newInstance(replyDestination, activeMQComponent);
// now we have the endpoint we can use regular Camel API to send a message to it
template.sendBody(endpoint, "Here is the late reply.");

응답을 보내는 다른 솔루션은 전송할 때 동일한 Exchange 속성에 replyDestination 개체를 제공하는 것입니다. Camel은 이 속성을 찾아서 실제 대상에 사용합니다. 그러나 엔드포인트 URI에는 더미 대상이 포함되어야 합니다. 예를 들면 다음과 같습니다.

// we pretend to send it to some non existing dummy queue
template.send("activemq:queue:dummy, new Processor() {
   public void process(Exchange exchange) throws Exception {
      // and here we override the destination with the ReplyTo destination object so the message is sent to there instead of dummy
      exchange.getIn().setHeader(JmsConstants.JMS_DESTINATION, replyDestination);
      exchange.getIn().setBody("Here is the late reply.");
    }
}