2016-07-28 96 views
0

我已經提到了Camel文檔的JMS頁面以及許多相關的SO問題such as this one,但我無法找到有關實現的完整列表。如何實現駱駝路由以接收來自JMS隊列的消息?

我使用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才能聽這個隊列?

+0

你有設置,將引用位置的任何豆或連接信息爲你排隊?連接工廠Spring指的是找不到的是JMS連接工廠,它告訴Camel JMS組件如何與您的隊列對話。你能否提供整個上下文xml,或者至少可以爲你的JMS隊列引用駱駝或spring bean的任何部分? – alexanderific

+0

請在問題中添加您的jms bean定義。 – Jayaraj

回答

1

您需要告訴Camel的jms組件使用哪個JMS連接工廠。如果您使用的是WebLogic,很可能您會從jndi中獲得。

在下面的示例中,我使用spring的jee:jndi-lookup(我相信這可能是您可以在WebLogic中使用的名稱)查找連接工廠。查找的工廠然後作爲ID爲myConnectionFactory的春豆提供。

此連接工廠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> 

重要提示:您將需要調整該進一步(安裝交易,設置併發消費者,可以配置彈簧JMS連接池)