0
votes

Using Spring boot @RabbitListener, we are able to process the AMQP messages. Whenever a message sent to queue its immediately publish to destination exchange. Using @RabbitListener we are able to process the message immediately. But we need to process the message only between specific timings example 1AM to 6AM. How to achieve that ?

1

1 Answers

1
votes

First of all you can take a look into Delayed Exchange feature of RabbitMQ: https://docs.spring.io/spring-amqp/docs/current/reference/html/#delayed-message-exchange

So, this way on the producer side you should determine how long the message should be delayed before it is routed to the main exchange for the actual consuming afterwards.

Another way is to take a look into Spring Integration and its Delayer component: https://docs.spring.io/spring-integration/docs/5.2.0.BUILD-SNAPSHOT/reference/html/messaging-endpoints.html#delayer

This way you will consume messages from the RabbitMQ, but will delay them in the target application logic.

And another way I see like start()/stop() the listener container for consumption and after according your timing requirements. This way the message is going to stay in the RabbitMQ until you start the listener container: https://docs.spring.io/spring-amqp/docs/current/reference/html/#containerAttributes