简体   繁体   中英

Can we restrict spring boot rabbitmq message processing only between specific timings?

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM