Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop consuming messages with @RabbitListener

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.

like image 531
greyby Avatar asked Dec 08 '16 09:12

greyby


1 Answers

  1. Give the @RabbitListener an id.
  2. Get a reference to the listener endpoint registry bean by autowiring etc.
  3. Calling stop() on the registry will stop all containers.
  4. Call getListenerContainer(id).stop() to stop an individual container.
like image 184
Gary Russell Avatar answered Nov 15 '22 09:11

Gary Russell