RabbitMQ 使用立即位和强制位

发布于 2024-11-16 10:15:23 字数 389 浏览 2 评论 0原文

我正在使用 RabbitMQ 服务器。

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

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

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

有人可以帮助我理解立即位字段和这种行为吗?另外,我无法理解强制位字段的概念。

I am using RabbitMQ server.

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.

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).

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流年里的时光 2024-11-23 10:15:23

immediatemandatory 字段是 AMQP 规范的一部分,并且也在 RabbitMQ 常见问题解答中进行了介绍,以阐明其实现者如何解释其含义:

强制

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

或者用我的话来说,“将此消息放入至少一个队列。如果不能,请将其发送回给我。”

立即

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

或者用我的话说,“如果至少有一个消费者连接到我的队列,此时可以立即传递消息,请立即将此消息传递给他们。如果没有消费者连接,那么就没有意义我的消息稍后被消耗,他们永远不会看到它,他们打瞌睡,他们输了。”

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:

Mandatory

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.

Or in my words, "Put this message on at least one queue. If you can't, send it back to me."

Immediate

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).

Or in my words, "If there is at least one consumer connected to my queue that can take delivery of a message right this moment, deliver this message to them immediately. If there are no consumers connected then there's no point in having my message consumed later and they'll never see it. They snooze, they lose."

つ低調成傷 2024-11-23 10:15:23

http://www.rabbitmq。 com/blog/2012/11/19/break-things-with-rabbitmq-3-0/

删除“立即”标志

发生了什么变化?我们取消了对
AMQP 的 basic.publish 上很少使用“立即”标志。

你到底为什么这么做?对“立即”的支持制作了许多部分
代码库变得更加复杂,特别是在镜像队列周围。它
也阻碍了我们提供实质性成果
镜像队列的性能改进。

我需要做什么?如果您只想发布消息
如果不立即消耗它们就会被丢弃,你可以
发布到 TTL 为 0 的队列。

如果您还需要您的发布商能够确定这已
发生后,您还可以使用 DLX 功能将此类消息路由至
另一个队列,发布者可以从中使用它们。

只是将公告复制到此处以供快速参考。

http://www.rabbitmq.com/blog/2012/11/19/breaking-things-with-rabbitmq-3-0/

Removal of "immediate" flag

What changed? We removed support for the
rarely-used "immediate" flag on AMQP's basic.publish.

Why on earth did you do that? Support for "immediate" made many parts
of the codebase more complex, particularly around mirrored queues. It
also stood in the way of our being able to deliver substantial
performance improvements in mirrored queues.

What do I need to do? If you just want to be able to publish messages
that will be dropped if they are not consumed immediately, you can
publish to a queue with a TTL of 0.

If you also need your publisher to be able to determine that this has
happened, you can also use the DLX feature to route such messages to
another queue, from which the publisher can consume them.

Just copied the announcement here for a quick reference.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文