26.17. 応答の遅れに JMSReplyTo を使用する
Camel を JMS リスナーとして使用する場合、キー ReplyTo
を持つ ReplyTo javax.jms.Destination
オブジェクトの値で Exchange プロパティーを設定します。この Destination
は次のように取得できます。
Destination replyDestination = exchange.getIn().getHeader(JmsConstants.JMS_REPLY_DESTINATION, Destination.class);
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.");
// 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.");
応答を送信する別のソリューションは、送信時に同じエクスチェンジプロパティーに replyDestination
オブジェクトを提供することです。その後、Camel はこのプロパティーを取得し、実際の宛先に使用します。ただし、エンドポイント URI にはダミーの宛先が含まれている必要があります。以下に例を示します。