spring-boot - 使用 Spring Integration XML 配置连接到多个 ActiveMQ 服务器
问题描述
几天来,我一直在尝试使用 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 实现相同的目标?
解决方案
好的,我明白了,对于一个简单的情况,我只需要像这样将正确的 connectionFactory 添加到适配器
<jms:message-driven-channel-adapter channel="jmsInChannel"
destination-name="queue.demo"
connection-factory="jmsConnectionFactory1" />
推荐阅读
- c++ - 如何从 __m64 值的 lsb 创建一个 8 位掩码?
- java - 使用 Mulesoft 或 Java 从 json 字符串中提取特定的 json 字段 [] 并存储在 HashMap 中
- java - 为什么 Spring ORM JpaTransactionManager 使用原生实体管理器工厂?
- mysql - 如何在mysql中使用join创建视图
- r - purrr auto.arima xreg 组合
- javascript - 从 Observable 中获取值
目的 - kubernetes - 无法更改 Kubernetes 日志目录
- node.js - 如何在 IBM Watson Conversation 中调用外部 API
- java - 在 glassfish 上以休眠方式缓存
- r - 使用 lapply 和 ifelse 的数据帧的子集列表