RabbitMQ:消息保持“未确认”状态 [英] RabbitMQ: messages remain "Unacknowledged"

查看:2895
本文介绍了RabbitMQ:消息保持“未确认”状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Java应用程序向RabbitMQ交换发送消息,然后交换重定向消息到绑定队列。
我使用带有RabbitMQ的Springframework AMQP java插件。

My Java application sends messages to RabbitMQ exchange, then exchange redirects messages to binded queue. I use Springframework AMQP java plugin with RabbitMQ.

问题:消息进入队列,但它仍处于未确认状态,它永远不会变为Ready 。

The problem: message comes to queue, but it stays in "Unacknowledged" state, it never becomes "Ready".

可能是什么原因?

推荐答案

未确认的消息意味着消费者已经读过它,但是消费者从来没有向RabbitMQ经纪人发回ACK说它已经完成处理它。

An Unacknowledged message implies that it has been read by your consumer, but the consumer has never sent back an ACK to the RabbitMQ broker to say that it has finished processing it.

我不是过分熟悉Spring Framework插件,但在某处(对于您的消费者),您将声明您的队列,它可能看起来像这样(取自 http://www.rabbitmq.com/tutorials/tutorial-two-java.html ):

I'm not overly familiar with the Spring Framework plugin, but somewhere (for your consumer) you will be declaring your queue, it might look something like this (taken from http://www.rabbitmq.com/tutorials/tutorial-two-java.html):

channel.queueDeclare(queueName, ....)

然后你将设置你的消费者

then you will setup your consumer

bool ackMode = false;
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(queueName, ackMode, consumer);

上面的ackMode是布尔值,通过设置为false,我们明确地告诉RabbitMQ我的消费者将承认给出的每条消息。如果此标志设置为true,那么您将不会在RabbitMQ中看到未确认的计数,而是只要消费者已将消息读取(即已将消息传递给消费者,它将从队列中删除它)。

ackMode above is a boolean, by setting it to false, we're explicitly saying to RabbitMQ that my consumer will acknowledge each message it is given. If this flag was set to true, then you wouldn't be seeing the Unacknowledged count in RabbitMQ, rather as soon as a consumer has read the message off (i.e it has been delivered to the consumer it will remove it from the queue).

要确认一条消息,您可以这样做:

To acknowledge a message you would do something like this:

QueueingConsumer.Delivery delivery = consumer.nextDelivery();
//...do something with the message...
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); //the false flag is to do with multiple message acknowledgement






如果您可以发布一些消费者代码,那么我可能会进一步帮助......但同时请看一下 BlockingQueueConsumer 具体来说:您将看到的构造函数可以设置 AcknowledgeMode 也看一看在nextMessage()这将返回一个Message对象,其中包含一个名为getDeliveryTag()的方法,这将返回一个Long,它是您将在basicAck上发回的ID


If you can post some of your consumer code then I might be able to help further...but in the mean time take a look at BlockingQueueConsumer specifically: the constructor you will see that you can set the AcknowledgeMode and also take a look at the nextMessage() this will return a Message object which contains a method called getDeliveryTag() this will return a Long which is the ID that you would send back on the basicAck

这篇关于RabbitMQ:消息保持“未确认”状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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