Spring JMS start listening to jms queues on request

↘锁芯ラ 提交于 2019-12-08 06:38:35

问题


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?


回答1:


This should work.

  1. Configure the @JmsListener with a dummy queue name and an id.
  2. Configure the listener container factory with autoStartup false.
  3. When you are ready, get a reference to the listener container using it's id from the JmsListenerEndpointRegistry (auto wire the registry into your app and call getListenerContainer(id)).
  4. Cast the container to an AbstractMessageListenerContainer and call setDestinationName (or setDestination) with the desired queue.
  5. start() it.


来源:https://stackoverflow.com/questions/40791567/spring-jms-start-listening-to-jms-queues-on-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!