我有一个在 tomcat 上运行的 Web 应用程序,并声明了 activemq 消费者。应用程序工作正常,但现在我想在运行时启动消费者 - 所以我声明了控制总线并向其发送消息。
有一段我的代码:
<channel id="controlChannel"/>
<control-bus input-channel="controlChannel"/>
<gateway service-interface="myApp.ControlGateway" default-request-channel="controlChannel"/>
<channel id="eventQueueChannel"/>
<jms:message-driven-channel-adapter
id="eventQueueJMSIn"
connection-factory="connectionFactory"
destination="eventQueue"
channel="eventQueueChannel"
auto-startup="false"
acknowledge="transacted"
concurrent-consumers="${concurrentConsumers:1}"
max-concurrent-consumers="${maxConcurrentConsumers:10}"/>
然后我通过 controlBusGateway.sendCommand("@eventQueueJMSIn.start()");
启动此网关。
问题是消费者无法连接到activemq。此外,发行商也存在问题。
总之,当一切自动启动时,就没有问题了。当我将消费者网关更改为 auto-startup="false"
时,我无法从 activemq 发送或接收任何消息。但是当我测试这个错误时,我假设如果 activemq 中有排队消息,它会连接到它并且一切正常。
我很惊讶出版商存在问题 - 我没有改变它。我不知道为什么它有时会起作用......
编辑:
有一个错误:
“org.apache.activemq.transport.tcp.TcpTransportFactory
无法转换为 org.apache.activemq.transport.TransportFactory
” - 在将 auto-startup
更改为 false 后出现。
我还看到,当一切正常时,Thread.currentThread().getContextClassLoader()
返回 BundleDelegatingClassLoader
,当抛出异常时,返回 AppClassLoader
。
最佳答案
如果不是开销,那么您可以尝试使用Camel Framework来实现所描述的场景。
关于java - 在运行时启动 jms 消息驱动的 channel 适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34360871/