簡體   English   中英

如何在駱駝中實現路由以從JMS隊列接收消息?

[英]How do I implement a route in camel to receive messages from a JMS queue?

我已經參考了Camel文檔的JMS頁面以及諸如此類的許多相關的SO問題,但是我無法找到有關實現的完整列表。

我正在將Spring XML和Camel和Weblogic一起用於服務器。 我用以下名稱創建了一個測試隊列:

服務器:TestJMSServer,模塊:TestJMSModule,隊列:TestJMSQueue,CF:TestConnectionFactory。

根據駱駝的文檔,我的路線應如下所示:

<camel:route id="test">
        <camel:from uri="jms:TestJMSQueue" />
        <camel:to uri="file:/Users/...." />
</camel:route>

這給我一個錯誤,提示“必須指定connectionFactory”。 那么,為了偵聽此隊列,我還需要添加到applicationContext.xml中的什么呢?

您需要告訴Camel的jms-component使用哪個JMS連接工廠。 如果您使用的是WebLogic,最有可能從jndi獲得。

在下面的示例中,我正在使用spring的jee:jndi-lookup連接工廠(我相信它甚至可能是您可以在WebLogic中使用的名稱)。 然后,已查找的工廠可以作為ID為myConnectionFactory的Spring bean使用。

然后,此連接工廠bean用於駱駝的JmsComponentconnectionFactory屬性。 注意id屬性: jms 這定義了要在您的路線中使用的駱駝端點uri方案。

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
       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">


    <jee:jndi-lookup id="myConnectionFactory" jndi-name="jms/connectionFactory"/>

    <route id="test" xmlns="http://camel.apache.org/schema/spring">
        <from uri="jms:TestJMSQueue"/>
        <to uri="file:/Users/...."/>
    </route>


    <bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
        <property name="connectionFactory" ref="myConnectionFactory"/>
        <!-- more configuration required based on your requirements -->
    </bean>

    <!--
    example uses  invm amq broker:

    <bean id="anothercnf" class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="vm://mybroker"/>
    </bean>
    -->
</beans>

重要說明 :您將需要進一步調整(設置事務,設置並發使用者,可能配置spring jms連接池)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM