RabbitMQ 使用立即数和强制位 [英] RabbitMQ use of immediate and mandatory bits

查看:32
本文介绍了RabbitMQ 使用立即数和强制位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 RabbitMQ 服务器.

I am using RabbitMQ server.

为了发布消息,我将 immediate 字段设置为 true 并尝试发送 50,000 条消息.使用rabbitmqctl list_queues,我看到队列中的消息数.

For publishing messages, I set the immediate field to true and tried sending 50,000 messages. Using rabbitmqctl list_queues, I saw that the number of messages in the queue was zero.

然后,我将 immediate 标志更改为 false 并再次尝试发送 50,000 条消息.使用 rabbitmqctl list_queues,我看到总共有 100,000 条消息在队列中(直到现在,没有消费者存在).

Then, I changed the immediate flag to false and again tried sending 50,000 messages. Using rabbitmqctl list_queues, I saw that a total of 100,000 messages were in queues (till now, no consumer was present).

之后,我启动了一个消费者,它消耗了所有 100,000 条消息.

After that, I started a consumer and it consumed all the 100,000 messages.

任何人都可以帮助我理解立即位域和这种行为吗?另外,我无法理解强制位域的概念.

Can anybody please help me in understanding about the immediate bit field and this behavior too? Also, I could not understand the concept of the mandatory bit field.

推荐答案

immediatemandatory 字段是 AMQP 规范的一部分,也包含在 RabbitMQ 中澄清实施者如何解释其含义的常见问题解答:

The immediate and mandatory fields are part of the AMQP specification, and are also covered in the RabbitMQ FAQ to clarify how its implementers interpreted their meaning:

强制

这个标志告诉服务器如何如果消息无法路由到,则做出反应一个队列.具体来说,如果强制是设置并运行绑定后消息被放置在零队列然后消息返回给发件人(带有基本的.return).如果强制没有被设置在相同的服务器会的情况默默地丢弃消息.

This flag tells the server how to react if a message cannot be routed to a queue. Specifically, if mandatory is set and after running the bindings the message was placed on zero queues then the message is returned to the sender (with a basic.return). If mandatory had not been set under the same circumstances the server would silently drop the message.

或者用我的话来说,将此消息放在至少一个队列中.如果不能,请将其发回给我."

立即

对于立即发布的消息设置,如果匹配的队列已准备好消费者然后其中之一将有消息路由到它.如果幸运的话消费者在确认之前崩溃收到消息将重新排队和/或交付给其他消费者该队列(如果没有崩溃消息已确认,一切都已完成照常).然而,如果一个匹配队列的就绪状态为零消费者消息不会排队等待随后的重新交付从那个队列.只有当所有的匹配队列没有准备好消息被返回的消费者给发件人(通过 basic.return).

For a message published with immediate set, if a matching queue has ready consumers then one of them will have the message routed to it. If the lucky consumer crashes before ack'ing receipt the message will be requeued and/or delivered to other consumers on that queue (if there's no crash the messaged is ack'ed and it's all done as per normal). If, however, a matching queue has zero ready consumers the message will not be enqueued for subsequent redelivery on from that queue. Only if all of the matching queues have no ready consumers that the message is returned to the sender (via basic.return).

或者用我的话来说,如果至少有一个消费者连接到我的队列,可以立即接收消息,请立即将消息传递给他们.如果没有连接的消费者,则没有重点是让我的消息稍后被消费,他们将永远不会看到它.他们打盹,他们输了."

这篇关于RabbitMQ 使用立即数和强制位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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