使用 Spring 集成 XML 配置连接到多个 ActiveMQ 服务器
Connecting to multiple ActiveMQ Servers using Spring Integration XML Configuration
几天来我一直在尝试使用 XML 配置在 Spring 集成中设置多个 ActiveMQ 连接。
我正在使用 spring 引导,SI 在上下文中查找名为 jmsConnectionFactory 的 bean 并使用它。但是,如果我必须 send/listen 向 from/to 不同的 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 启动应用程序时出现此错误:
***************************
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.
我遇到了这个解决方案, it's a java configuration. Also I looked into this but it's using camel
有没有办法使用 XML 配置为 Spring 集成实现同样的效果?
好的,我明白了,对于一个简单的案例,我只需要像这样向适配器添加正确的 connectionFactory
<jms:message-driven-channel-adapter channel="jmsInChannel"
destination-name="queue.demo"
connection-factory="jmsConnectionFactory1" />
几天来我一直在尝试使用 XML 配置在 Spring 集成中设置多个 ActiveMQ 连接。
我正在使用 spring 引导,SI 在上下文中查找名为 jmsConnectionFactory 的 bean 并使用它。但是,如果我必须 send/listen 向 from/to 不同的 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 启动应用程序时出现此错误:
***************************
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.
我遇到了这个解决方案,
有没有办法使用 XML 配置为 Spring 集成实现同样的效果?
好的,我明白了,对于一个简单的案例,我只需要像这样向适配器添加正确的 connectionFactory
<jms:message-driven-channel-adapter channel="jmsInChannel"
destination-name="queue.demo"
connection-factory="jmsConnectionFactory1" />