0

My code sends a batch of messages to multiple RabbitMQ Consumers and once the last message is consumed, I want to trigger a method. The timing to trigger the method has to to be after all messages because it uses data from all the message processing.

Is there a way to do that with spring-amqp?

Glide
  • 20,235
  • 26
  • 86
  • 135
  • Define "all messages consumed"... Is that because the MQ provider stopped sending messages? If yes, how do you detect that? – fge Feb 29 '16 at 16:40
  • @fge I'm processing messages in "cycles", so I could potentially insert a dummy start and end messages into the queue. When the "end" message is processed, I want to wait until all other messages are processed then trigger the method. That's what I mean by "all messages consumed". – Glide Feb 29 '16 at 17:46

1 Answers1

1

The upcoming 1.6 release (currently 1.6.0.M1 - first milestone release) has a new feature to emit application events when the container goes idle.

With earlier versions you have to arm a timer (scheduled task) yourself and cancel then re-arm it whenever a message arrives.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thanks! Do you know if I can achieve it by using `spring-batch` and have a `AmqpWriter` in a `step` and would having my code inside `StepExecutionListener.afterStep()` guarantee it to be triggered after all messages are processed? – Glide Feb 29 '16 at 17:51
  • Not sure what you mean by `AmqpWriter` in this context; you could wrap a `RabbitTemplate` in an `ItemReader` and, when `receive()` returns `null` it would indicate the end of the step. – Gary Russell Feb 29 '16 at 18:01