将消息返回到Rabbitmq的队列末尾 [英] Return message to the end of queue in rabbitmq

查看:867
本文介绍了将消息返回到Rabbitmq的队列末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有交流和排队.生产者不需要消费确认,但是在某些情况下,由于缺少其他数据,消费者当前可能无法处理消息.因此,我想将这些消息返回到队列末尾.这该怎么做?还是我拒绝邮件时自动完成?

I have exchange and queue. Producer doesn't need consumption confirmation, but messages in some cases can be un-processable by consumer in current moment, because of lack of other data. Because of this, I want to return those messages to the end of queue. How to do this? Or is it done automatically when I reject message?

流量:

  • Message1被消耗并在数据库中创建一些记录.
  • Message2被消耗,并检查数据库中是否有记录,如果是,则更新记录.如果数据库中没有记录,则应将消息返回到队列末尾.

因此,存在消息排序问题,在一般情况下,我会按顺序获取消息,因为大多数组件都正确地传递了消息.我想解决潜在的情况,当Message1的生产者由于负担重或其他原因而无法立即交换消息时.在这种情况下,将首先使用Message2,但数据库中将没有足够的信息来处理它.我希望此消息返回到队列,但请确保此Message2将转到队列的末尾.如果要解决的话,如果我只使用一个队列,我将陷入无限循环.

So there is message ordering problem and in general situation I get messages in order, because most of components deliver their messages correctly. I want to solve potential situation, when Producer of Message1 wasn't able to put message to exchange immediately because of heavy load or other reason. In this situation, Message2 will be consumed first but there will be no sufficient informations in database to process it. I want this message to be returned back to queue, but be sure that this Message2 will go to the tail of queue. If it will go to head, I will get infinite loop if I use only one queue.

另一个问题是,是否有可能跟踪消费者尝试处理消息但返回了多少次.如果有可能像我之前描述的那样将消息放入队列尾部,但是由于某种原因,Message1的生产者死亡,并且将没有Message1,我想在重试几次或一段时间后使Message2死亡.

Side question is, if it's possible to track how many times consumers tried to process message but returned it. If there is possibility to put message to the tail of queue like I described before, but for some reason Producer of Message1 died, and there will be no Message1, I want to make Message2 dead after some number of retries or some time.

推荐答案

RabbitMQ始终将拒绝的消息放在队列的开头.要将它们放在最后,您必须自己发布(例如,使用RabbitTemplate).您可以添加带有重试次数的标题.

RabbitMQ always puts rejected messages at the head of the queue. To put them at the tail, you will have to publish them yourself (e.g. using RabbitTemplate). You can add a header with a count of retries.

这篇关于将消息返回到Rabbitmq的队列末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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