0

we are using @RabbitListener to listen to the queue and when there are messages we process them. However I want to do some reporting task when queue is empty, this happens when our app just processed tons of messages in the queue and no more message for a while. that's the time I want to report. How can i do that with @RabbitListener?

here is my code:

@RabbitListener(queues = "${consumer.queue}", containerFactory = "ListenerContainerFactory")
    public void handleMessage(Message message) {
        processEvent(message);
    }
user468587
  • 4,799
  • 24
  • 67
  • 124

1 Answers1

1

As I answered your other question a few weeks ago there is no mechanism in AMQP (and hence Spring AMQP) to notify the consumer that there are currently no messages in the queue.

We could modify the container to fire an ApplicationEvent once, when no message is found after messages have been processed, but that would require a modification to the framework. Your listener would have to implement ApplicationListener to get such an event.

Feel free to open a New Feature JIRA Issue if you want and we might be able to take a look at it.

Community
  • 1
  • 1
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • You are right, I've added extra message to mark the end of the job, and in rabbit listener, once it receives the 'job end' message , it starts reporting. I'm new to spring AMQP and not sure if this is a common situation that requires rabbit listener to be able to do some extra work when queue is empty, but think it would be nice feature to provide. Thanks! – user468587 Oct 12 '15 at 19:24