【问题标题】:How do I implement a route in camel to receive messages from a JMS queue?如何在骆驼中实现路由以接收来自 JMS 队列的消息?
【发布时间】:2016-07-28 13:40:48
【问题描述】:

我参考了 Camel 文档的 JMS 页面和许多相关的 SO 问题 such as this one,但我无法找到有关实施的完整列表。

我将 Spring XML 与 Camel 和 Weblogic 一起用于服务器。我创建了一个具有以下名称的测试队列:

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

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

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

这给了我一个错误,说“必须指定连接工厂”。那么,为了收听这个队列,我还需要添加什么到 applicationContext.xml 中?

【问题讨论】:

  • 您是否设置了任何 bean 来为您的队列引用位置或连接信息? Spring 所指的连接工厂是 JMS Connection Factory,它告诉 Camel JMS 组件如何与您的队列对话。您能否为您提供整个上下文 xml,或者至少为您的 JMS 队列提供引用骆驼或弹簧豆的任何部分?
  • 请在问题中添加您的 jms bean 定义。

标签: java spring apache-camel weblogic spring-jms


【解决方案1】:

你需要告诉 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 连接池)

【讨论】:

    猜你喜欢
    • 2016-02-06
    • 2018-09-02
    • 1970-01-01
    • 1970-01-01
    • 2012-01-19
    • 2014-10-06
    • 1970-01-01
    • 1970-01-01
    • 2014-08-03
    相关资源
    最近更新 更多