如何停止使用@RabbitListener 消费消息 [英] How to stop consuming messages with @RabbitListener
本文介绍了如何停止使用@RabbitListener 消费消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用 MessageListenerAdapter 处理消息时,我可以调用 SimpleMessageListenerContainer.stop() 来停止从队列中消费.但是我改用@RabbitListener 监听后,就找不到这样的方法了.我试过 CachingConnectionFactory.stop() 但不起作用.有人可以帮忙吗?非常感谢.
When I use MessageListenerAdapter to handle message, I could call SimpleMessageListenerContainer.stop() to stop consume from the queue. But after I change to use @RabbitListener to listen, I can't find a method like this. I tried CachingConnectionFactory.stop() but doesn't work. Could anyone help? Thank you very much.
推荐答案
- 给
@RabbitListener
一个id
. - 获取对 侦听器端点注册表 bean 通过自动装配等.
- 在注册表上调用
stop()
将停止所有容器. - 调用
getListenerContainer(id).stop()
来停止单个容器.
- Give the
@RabbitListener
anid
. - Get a reference to the listener endpoint registry bean by autowiring etc.
- Calling
stop()
on the registry will stop all containers. - Call
getListenerContainer(id).stop()
to stop an individual container.
这篇关于如何停止使用@RabbitListener 消费消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文