178.16. 遅延応答に対する JMSReplyTo の使用


Camel を JMS リスナーとして使用する場合、キー ReplyTo を持つ ReplyTo javax.jms.Destination オブジェクトの値で Exchange プロパティーを設定します。この Destination は次のように取得できます。

Copy to Clipboard Toggle word wrap
Destination replyDestination = exchange.getIn().getHeader(JmsConstants.JMS_REPLY_DESTINATION, Destination.class);

そして後でそれを使用して、通常の JMS または Camel を使用して応答を送信します。

Copy to Clipboard Toggle word wrap
    // 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 にはダミーの宛先を含める必要があります。以下に例を示します。

Copy to Clipboard Toggle word wrap
    // 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.");
        }
    }
トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat, Inc.