Spring rabbitlistner stop listening to queue using annotation syntax

浪尽此生 提交于 2019-12-06 10:04:24

To get messages on-demand, it's generally better to use rabbitTemplate.receiveAndConvert() rather than a listener; that way you completely control when you receive messages.

Starting with version 1.5 you can configure the template to block for some period of time (or until a message arrives). Otherwise it immediately returns null if there's no message.

The listener is really designed for message-driven applications.

If you can block the thread in the listener until the job completes, no more messages will be delivered - by default the container has only one thread.

If you can't block the thread until the job completes, for some reason, you can stop()/start() the listener container by getting a reference to it from the Endpoint Registry.

It's generally better to stop the container on a separate thread.

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