[英]Can we restrict spring boot rabbitmq message processing only between specific timings?
Using Spring boot @RabbitListener, we are able to process the AMQP messages. 使用Spring boot @RabbitListener,我们能够处理AMQP消息。 Whenever a message sent to queue its immediately publish to destination exchange.
每当消息发送到队列中时,其立即发布到目标交换。 Using @RabbitListener we are able to process the message immediately.
使用@RabbitListener,我们可以立即处理消息。 But we need to process the message only between specific timings example 1AM to 6AM.
但是我们只需要在特定的时间(例如1AM到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 首先,您可以查看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 另一种方法是查看Spring Integration及其
Delayer
组件: 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. 这样,您将使用来自RabbitMQ的消息,但会在目标应用程序逻辑中延迟它们。
And another way I see like start()/stop()
the listener container for consumption and after according your timing requirements. 还有另一种方式,我可以像
start()/stop()
监听容器并根据您的时序要求进行消费。 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 这样,消息将一直保留在RabbitMQ中,直到您启动侦听器容器为止: https : //docs.spring.io/spring-amqp/docs/current/reference/html/#containerAttributes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.