Reputation: 130
We are using Spring AMQP library to consume messages from Queues in RabbitMQ. Our publisher produces variable number of messages on known schedules, So we are thinking about start Consumers to on schedule and stop once Queue is empty.
I am wondering how to gracefully close channel and connetion when Queue length reaches Zero?
Upvotes: 0
Views: 782
Reputation: 174494
The upcoming 1.6 release (the release candidate was released last week, the GA is due at the end of next week) has a new feature to emit events when the listener container goes idle.
You can stop the container when such an event is received. You should not stop the container on the thread that the event listener is called on - instead pass the event to a new thread. If you try to stop the container on the same thread it will cause a delay because the container waits for the thread to be released.
Upvotes: 4