5

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.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
greyby
  • 156
  • 1
  • 8

1 Answers1

9
  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.
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • @Garry What if we want to gracefully stop consuming messages? Please see my question https://stackoverflow.com/questions/55991826/how-to-gracefully-stop-consuming-messages-with-rabbitlistener – user634545 May 05 '19 at 12:17