【问题标题】:Connecting to multiple ActiveMQ Servers using Spring Integration XML Configuration使用 Spring Integration XML 配置连接到多个 ActiveMQ 服务器
【发布时间】:2020-01-07 01:14:42
【问题描述】:

我这几天一直在尝试使用 XML 配置在 Spring Integration 中设置多个 ActiveMQ 连接。

我正在使用spring boot,SI在上下文中寻找一个名为jmsConnectionFactory的bean并使用它。但是,如果我必须从不同的 ActiveMQ 服务器发送/收听 jms 消息怎么办?

我现在拥有的是这样的:

<bean id="jmsConnectionFactory1"
    class="org.springframework.jms.connection.CachingConnectionFactory">
    <property name="targetConnectionFactory">
        <bean class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL" value="tcp://localhost:61616" />
        </bean>
    </property>
    <property name="sessionCacheSize" value="10" />
    <property name="cacheConsumers" value="false" />
</bean>

<bean id="jmsConnectionFactory2"
    class="org.springframework.jms.connection.CachingConnectionFactory">
    <property name="targetConnectionFactory">
        <bean class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL" value="tcp://192.168.1.59:61616" />
        </bean>
    </property>
    <property name="sessionCacheSize" value="10" />
    <property name="cacheConsumers" value="false" />
</bean>
...
<jms:message-driven-channel-adapter channel="jmsInChannel" destination-name="queue.demo" />
<int:channel id="jmsInChannel" />
...

尝试启动 spring boot 应用程序时出现此错误:

***************************
APPLICATION FAILED TO START
***************************

Description:

A component required a bean named 'jmsConnectionFactory' that could not be found.

The following candidates were found but could not be injected:
- Bean method 'jmsConnectionFactory' in 'ActiveMQXAConnectionFactoryConfiguration' not loaded because @ConditionalOnClass did not find required class 'javax.transaction.TransactionManager'


Action:

Consider revisiting the entries above or defining a bean named 'jmsConnectionFactory' in your configuration.

我遇到了这个解决方案,https://stackoverflow.com/a/43401330/3367392 这是一个 java 配置。我也调查了这个,但它使用的是骆驼https://stackoverflow.com/a/13288312/3367392

有没有办法使用 XML 配置为 Spring Integration 实现相同的功能?

【问题讨论】:

    标签: spring-boot spring-integration activemq javabeans spring-jms


    【解决方案1】:

    好的,我明白了,对于一个简单的情况,我只需将正确的 connectionFactory 添加到这样的适配器中

    <jms:message-driven-channel-adapter channel="jmsInChannel"
        destination-name="queue.demo"
        connection-factory="jmsConnectionFactory1" />
    

    【讨论】:

    • 对。这就是我要说的。您应该通过单击复选标记来接受您自己的答案。
    • 是的,会的,不过我得等两天,谢谢你路过@Gary Russell :)
    猜你喜欢
    • 2015-06-11
    • 1970-01-01
    • 2012-03-22
    • 1970-01-01
    • 2017-09-16
    • 2013-06-02
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多