2016-07-28 146 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连接池)