有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在camel中实现路由以从JMS队列接收消息?

我已经参考了Camel文档的JMS页面和许多相关的SO问题such as this one,但是我无法找到关于实现的全面列表

我正在为服务器使用SpringXML以及Camel和Weblogic。我用以下名称创建了一个测试队列:

服务器:TestJMSServer,模块:TestJMSModule,队列:TestJMSQueue,CF:TestConnectionFactory

根据Camel文档,我的路线应该如下所示:

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

这给了我一个错误,说“必须指定connectionFactory”。那么,我还需要向applicationContext添加什么呢。xml以侦听此队列


共 (1) 个答案

  1. # 1 楼答案

    您需要告诉Camel的jms组件要使用哪个jms连接工厂。如果您使用的是WebLogic,那么您很可能会从jndi获得这些信息

    在下面的示例中,我使用spring的jee:jndi-lookup查找连接工厂(我相信这甚至可能是您可以在WebLogic中使用的名称)。然后,查找的工厂将作为id为myConnectionFactory的Springbean提供

    然后,这个连接工厂bean用于camel的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连接池)