如何设置一个重试次数在RabbitMQ的呢? [英] How do I set a number of retry attempts in RabbitMQ?

查看:14846
本文介绍了如何设置一个重试次数在RabbitMQ的呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用RabbitMQ的,我有一个队列中保存电子邮件。我的消费服务去队列中的消息,并试图向他们发送。如果由于某种原因,我的消费者根本无法发送消息,我想重新入队的消息再次发送。我知道我可以做一个basicNack并设置重新排队标志是真实的,但是,我不想无限期地重新排队消息(比方说,如果我们的邮件系统出现故障,我不想继续重新排队未发送的邮件)。我想定义的时候,我可以重新排队的消息被再次发送的数量有限。我无法设置字段中的电子邮件对象,但是,当我出列,并发送NACK。更新的字段不是在队列中的消息present。有,我可以处理这个任何其他方式?先谢谢了。

I am using RabbitMQ and I have a queue that holds email messages. My consumer service de-queues messages and attempts to send them. If, for any reason, my consumer cannot send the message, I would like to re-queue the message to send again. I realize I can do a basicNack and set the requeue flag to be true, however, I don't want to requeue the message indefinitely (say, if our email system goes down, I don't want to continuously requeue unsent messages). I would like to define a finite number of times that I can requeue the message to be sent again. I can't set a field on the email message object, however, when I dequeue it and send a nack. The updated field is not present on the message in the queue. Is there any other way in which I can approach this? Thanks in advance.

推荐答案

有没有这样的功能,像重试次数在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".

这篇关于如何设置一个重试次数在RabbitMQ的呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆