Spring JMS根据请求开始侦听jms队列 [英] Spring JMS start listening to jms queues on request
本文介绍了Spring JMS根据请求开始侦听jms队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Spring提供了@JMSListener
批注,以侦听来自特定队列的消息.还有实施JmsListenerConfigurer
并注册MessageListener
.
Spring provides @JMSListener
annotation to listen to messages from a particular queue. There is also an alternative to implement JmsListenerConfigurer
and register a MessageListener
.
在两种情况下,都必须在应用程序启动时通过对代码进行硬编码或通过属性来知道队列的名称.
In both the cases, the name of the queue has to be known at the time when the application starts, either by hardcoding in the code or via properties.
是否有一种方法可以监听在应用程序启动后很久才知道其名称的队列?
Is there a way to listen to a queue whose name is known to the application much later after it started?
推荐答案
这应该有效.
- Configure the
@JmsListener
with a dummy queue name and anid
. - Configure the listener container factory with
autoStartup
false. - When you are ready, get a reference to the listener container using it's
id
from theJmsListenerEndpointRegistry
(auto wire the registry into your app and callgetListenerContainer(id)
). - Cast the container to an
AbstractMessageListenerContainer
and callsetDestinationName
(orsetDestination
) with the desired queue. start()
it.
这篇关于Spring JMS根据请求开始侦听jms队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文