简体   繁体   English

我们可以仅在特定时间之间限制spring boot rabbitmq消息处理吗?

[英]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.

相关问题 我们如何在春季启动时将巨大的有效载荷限制为POST请求 - How can we restrict the huge payload to POST request in spring boot 多个用户如何使用Spring Boot使用Rabbitmq发送消息 - how can multiple users send message with rabbitmq using spring boot Rabbitmq + Spring Boot +消费者在处理一条消息后闲置15分钟 - rabbitmq + spring boot + consumers idle for 15 mins after processing a single message Spring boot rabbitmq消息没有被重新排队 - Spring boot rabbitmq message not getting requeued 在Spring Boot自定义RabbitMQ消息反序列化 - Customize RabbitMQ message deserialization in Spring Boot 使用@SentTo通过Spring Boot和RabbitMq发送消息 - Use @SentTo to send a message with Spring Boot and RabbitMq 我们可以为特定的 URI 启用 Spring 引导压缩吗? - Can we enable Spring boot compression for specific URIs? RabbitMQ Spring AMQP-一段时间后的消息处理 - RabbitMQ Spring AMQP - Message Processing after some time 仅健康检查后端 spring-boot 应用程序(消息处理应用程序) - Health check back-end only spring-boot application (message processing application) 如何在Spring Boot Rabbitmq中识别消息路由到的交换机? - How to identify the exchange to which the message is routed to in Spring boot rabbitmq?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM