RabbitMQ message latency delay limit is how much?

Before the time of writing Spring Cloud Stream thematic content, specifically introduction about how to use the delay to achieve timing RabbitMQ messaging tasks . Just recently we met because the development course of discovery, the message is not delayed effect, the message was directly consumed situation. Therefore continue in-depth study about the cause of the problem, in this record, to encounter similar problems of children's shoes reference.

identify the problem

Because not all messages have appeared in news without delay factor effect through message feature in question, roughly speculation may be delayed for too long leads to message delay failure. To test this reason, prior to acquire the article in the example, to test whether the delay time is directly related to the problem.

With the sample prior to the delay message (Git repository text at the end of obtaining a complete code) micro interfaces do something changed, it adds a request parameter delaydelay time to control:

@GetMapping("/sendMessage")
public String messageWithMQ(@RequestParam String message, @RequestParam Long delay) {
    log.info("Send: " + message);
    testTopic.output().send(MessageBuilder.withPayload(message).setHeader("x-delay", delay).build());
    return "ok";
}
复制代码

Then try to initiate the two requests:

Request 1 : 5000 milliseconds delay. After the message is sent to the MQ indeed after a delay of five seconds to get the consumer without any problems.

curl localhost:8080/sendMessage?message=hello&delay=5000
复制代码

Request 2 : Delay of 1 (31,536,000,000 milliseconds). After the message is sent to the MQ immediately consumed by consumers, there is no delay effect.

curl localhost:8080/sendMessage?message=hello&delay=31536000000
复制代码

Summary problem

In the clear after the cause of the problem, we need time to do some of the functions clearly defined (limit delay time), in order to avoid similar problems again. Depth exploration continues, major failure here has a direct relationship with the expiration time of the message (TTL). In RabbitMQ, the expiration time of the message must be non-negative 32-bit integer that: 0 <= n <= 2 ^ 32-1, in milliseconds. Wherein 2 ^ 32-1 = 4,294,967,295.

Here we can try the following two requests, respectively, the delay time is set HE 4294967295 4294967296:

curl localhost:8080/sendMessage?message=hello&delay=4294967295
curl localhost:8080/sendMessage?message=hello&delay=4294967296
复制代码

It can be found, when the delay time is 4,294,967,295 milliseconds when the delay message work; 4294967296 milliseconds when the delay time when the message is directly consumed, no delay effect.

Therefore, we use RabbitMQ messaging delay time, it must be noted that the delay limit is 4294967296 milliseconds. If your business needs will exceed this threshold, it is necessary to avoid the pit, use other methods to achieve the required delay or timing of execution of the task.

The sample code

Readers can view the examples in this article by the following warehouse in stream-delayed-message items:

If you are interested in these, welcomed the star, follow, bookmarking, forwarding support!

I welcome the attention of the public number: Program ape DD, get exclusive organize learning resources and push dry goods daily. If you are interested in my topic content, you can focus on my blog: didispace.com

Guess you like

Origin juejin.im/post/5d356edd51882503ea1c6464