且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何设置一个重试次数在RabbitMQ的呢?

更新时间:2022-02-17 15:37:51

有没有这样的功能,像重试次数在RabbitMQ的(以及在AMQP协议)。

There are no such feature like retry attempts in RabbitMQ (as well as in AMQP protocol).

可能的解决方案来实现重试次数限制的行为:

Possible solution to implement retry attempts limit behavior:

  1. 重新传递消息,如果它不是previously交还(检查交还的参数 basic.deliver 方法 - 你的图书馆应该有这方面的一些接口),并把它比抓在一纸空文交换,然后莫名其妙的过程。

  1. Redeliver message if it was not previously redelivered (check redelivered parameter on basic.deliver method - your library should have some interface for this) and drop it and than catch in dead letter exchange, then process somehow.

每一次消息无法处理再次发布,但设置或递增/递减头提起,说 X-交还计数(你可以选择任何名称您像,虽然)。为了克服重复传递控制在这种情况下,你必须检查现场设置是否达到某一限度(顶部或底部 - 0是我的choise,一拉 TTL IP头从TCP / IP)。

Each time message cannot be processed publish it again but set or increment/decrement header filed, say x-redelivered-count (you can chose any name you like, though). To get control over redeliveries in this case you have to check field you set whether it reaches some limit (top or bottom - 0 is my choise, a-la ttl in ip header from tcp/ip).

存储信息的唯一键(比如UUID,但你必须手动设置它,当你发布的消息)在Redis的,内存缓存或其他存储,即使是在MySQL的旁边有重复传递计数,然后在每个交还递增/递减该值,直到它达到极限。

Store message unique key (say uuid, but you have to set it manually when you publish message) in Redis, memcache or other storage, even in mysql alongside with redeliveries count and then on each redelivery increment/decrement this value until it reach the limit.

(真正的极客)写插件像你想将实现这样的行为。

(for real geeks) write plugin that will implement such behavior like you want.

#亲3 是重新传递消息留在队列头。如果你有长队,或者如果邮件定购重要的是你(注,即重复传递将打破严格的消息顺序,请参阅官方文档的详细信息,或者这是很重要的这个问题上的SO )。

The pro of #3 is that redelivered message stay in queue head. This is important if you have long queue or if messages order is important for you (note, that redeliveries will break strict messages order, see official docs for details or this question on SO).

P.S:

目前这个主题类似的回答,但在PHP。看一下吧,也许它可以帮助你一点(开始读它的话的有很多种方法来处理周期重新发货的问题的。

There is similar answer in this topic, but in php. Look through it, maybe it helps you a bit (start reading it from words "There are multiple techniques to deal with cycle redeliver problem".