在运行时启动jms消息驱动的通道适配器



我有一个在tomcat上运行的web应用程序,声明了activemq使用者。应用程序运行良好,但现在我想在运行时启动consumer,所以我声明了控制总线并向其发送消息。

我有一段代码:

<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的任何消息。但当我测试这个bug时,我假设如果在activemq中有排队消息,它会连接到它,一切都会正常进行。

我很惊讶,出版商有问题——我没有改变它。我不知道为什么它有时会起作用。。。

编辑:

出现错误:"org.apache.activemq.transport.tcp.TcpTransportFactory无法强制转换为org.apache.activemq.transport.TransportFactory"-在将auto-startup更改为false后出现。

我还看到,当一切正常时,Thread.currentThread().getContextClassLoader()返回BundleDelegatingClassLoader,当抛出异常时返回AppClassLoader

如果这不是开销,那么您可以尝试使用Camel Framework来实现所描述的场景。

相关内容

最新更新