Spring JMS根据请求开始侦听jms队列 [英] Spring JMS start listening to jms queues on request

查看:100
本文介绍了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?

推荐答案

这应该有效.

  1. @JmsListener配置一个虚拟队列名称和一个id.
  2. 配置
  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.

这篇关于Spring JMS根据请求开始侦听jms队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆