Expired Message Delivery Sequence RabbitMQ

亡梦爱人 提交于 2020-02-02 12:59:12

问题


We are building a solution in which we are publishing message to a time-out queue. After TTL expiry messages are pushed to main queue for re-processing.

We are setting up counter value so that messages will be tried for x no. of times for the redelivery.

Solution is working fine. But the scenario is when the message on the head position is highest TTL is not expired, other messages of lower expiry will not be re-published (to main queue).

Is this understanding correct ? If Yes what is the solution so that each message re-processed just after TTL.

Appreciating answers / viewpoint.

Thanks.


回答1:


If you use per-queue message TTL, then message expires and get removed from queue from head to tail (in the same order they was published).

When you use per-message TTL, then messages removed from queue only when they reach queue head, so situation when expired messages still reside in the middle of queue is normal. Such messages will not be send to consumer, and will be deadlettered (or dropped), but due to strict FIFO nature or RabbitMQ's queues that will happen as written above, when they reach queue head and delay before removal may be greater than actual message TTL. For example, if there are two message, first with TTL=10sec and the second one with TTL=1sec, second message will be deadlettered also in 10sec while it stay after first one.

To deal with messages that has different TTL, common workaround is to declare few queues, each for messages with same TTL or almost same, say, with precision 10sec. Actual precision may vary while it very application-specific and somehow empirical value.

If you will pick separate per-TTL queues, use per-queue TTL rather than per-message TTL for ease of messages workflow and to prevent disambiguation of understanding what happens with messages. Developers after you will thank you for that.

To re-process messages after their TTL use Dead Letter Exchanges, but beware of cycled messages problem: if RabbitMQ broker detects that your messages workflow cycled (messages get published to same exchange with the same routing key after it was deadlettered from it), it will silently drop message.




回答2:


the queue ttl is simple enough and working fine. but set per message ttl is not working expectly: each message publish to online consumer just after ttl.

why rabbitmq provide this feature? for which biz scenario?



来源:https://stackoverflow.com/questions/26206512/expired-message-delivery-sequence-rabbitmq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!