2

JMS と Camel はまったくの初心者です

これがシナリオです

Spring Web アプリケーション、JMS (ActiveMQ)、Camel があります。

Web アプリケーションは、camel を介して非同期で JSM に情報を送信する必要があります。つまり、Camel に情報を送信した後、Web サイトは応答を待つべきではありません。Web ページは続行する必要があります。

そして、私のアプリケーションは、キュー内の応答についてキューをリッスンする必要があります。応答が受信されると、特定の Bean を呼び出す必要があります。

これは可能ですか?

これは私のクライアントの構成です

ラクダのコンテキスト:

<!-- START SNIPPET: e1 -->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xsi:schemaLocation="
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
  <!-- END SNIPPET: e1 -->

  <!-- START SNIPPET: e2 -->
  <camel:camelContext id="camel-client">
    <camel:template id="camelTemplate"/>
  </camel:camelContext>
  <!-- END SNIPPET: e2 -->

  <!-- START SNIPPET: e3 -->
  <!-- Camel JMSProducer to be able to send messages to a remote Active MQ server -->
  <bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="brokerURL" value="tcp://localhost:61610"/>
  </bean>
  <!-- END SNIPPET: e3 -->

</beans>

キャメルコード:

ApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");

// get the camel template for Spring template style sending of messages (= producer)
ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);

System.out.println("Invoking the multiply with 22");
// as opposed to the CamelClientRemoting example we need to define the service URI in this java code
int response = (Integer)camelTemplate.sendBody("jms:queue:numbers", ExchangePattern.InOut, 22);
System.out.println("... the result is: " + response);

これはうまくいっています。しかし問題は、これは同期です。

これを非同期にしたい。

どうやってするの

4

2 に答える 2

0

答えは簡単です

int response = (Integer)camelTemplate.sendBody("jms:queue:numbers", ExchangePattern.InOut, 22);

これは

int response = (Integer)camelTemplate.sendBody("jms:queue:numbers",22);

言及しExchangePatternないでください。

教訓:ドキュメントを正しく読んでください。

于 2013-07-23T11:36:52.013 に答える
0

Camel Remoting の例では、これらすべてを実行する必要はありません (これは、最初から使用していると思われます)。

したがって、キューを介していくつかの処理をステージングする必要があります。これを誤解しないように:

Web Request -> JMS queue -> Camel -> Bean -> Done

ルートを作成します。

<camel:camelContext id="camel-client">
   <camel:template id="camelTemplate"/>
   <camel:route>
      <camel:from uri="jms:queue:myQueue"/>
      <camel:bean ref="someBean"/>
    </camel:route>
</camel:camelContext>

次に、コードでメッセージを送信するだけです: camelTemplate.asyncSendBody("jms:queue:myQueue", ExchangePattern.InOnly, someData);

于 2013-01-22T19:00:12.157 に答える