[英]Get all messages in queue at once (Spring Boot JMSListerner annotation)
I have a peculiar requirement to get all the pending messages on a queue for processing them further.我有一个特殊的要求,即获取队列中的所有待处理消息以进一步处理它们。 To elaborate.详细说明。 this is what is going to be the flow of the application:这就是应用程序的流程:
MessageListenerContainer
's stop()
method.默认情况下,使用MessageListenerContainer
的stop()
方法停止此队列的侦听器。listenerContainer.start()
队列中的消息将通过调用listenerContainer.start()
按需listenerContainer.start()
listenerContainer.start();
稍后会在listenerContainer.start();
时再次读取这些内容listenerContainer.start();
is invoked on demand.按需调用。For example:例如:
Let's say we have a queue named abc-queue
.假设我们有一个名为abc-queue
。 There's a JMS listener configured as:有一个 JMS 侦听器配置为:
@JmsListener(destination = "abc-queue", containerFactory = "abcFactory", selector = "_type='java.util.LinkedHashMap'", id = "abc-listener")
On app startup, we will do this:在应用程序启动时,我们将执行以下操作:
MessageListenerContainer listenerContainer = jmsListenerEndpointRegistry.getListenerContainer("abc-listener"); listenerContainer.stop();
App will have a controller endpoint to listen to this queue on demand.应用程序将有一个控制器端点来按需侦听此队列。 Once that's called, this will happen:一旦被调用,这将发生:
MessageListenerContainer listenerContainer = jmsListenerEndpointRegistry.getListenerContainer("abc-listener"); listenerContainer.start(); // now read all the messages in queue at once and store them in a list // listenerContainer.stop(); // start processing the messages one by one
Questions:问题:
listenerContainer.start()
doesn't start processing the queue immediately.即使队列中存在消息, listenerContainer.start()
也不会立即开始处理队列。 It's triggered only after another message appears on the queue.只有在队列中出现另一条消息后才会触发它。Any useful pointers are appreciated.任何有用的指针表示赞赏。
Potential solutions:可能的解决方案:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.