RabbitMQ 使用立即位和强制位

标签 rabbitmq amqp

我正在使用 RabbitMQ 服务器。

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

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

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

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

最佳答案

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

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.

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

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

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

关于RabbitMQ 使用立即位和强制位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6386117/

相关文章:

node.js - Node Js/Typescript - AMQP 消费者

RabbitMQ 直接回复和关联 ID

java - 入站和出站网关 AMQP 注释

java - 将不同类型的事件发布到不同的队列

spring - RabbitTemplate接收消息并重新排队

node.js - 如何在nodejs上使用RabbitMQ的消息

rabbitmq - 是否可以直接从命令行查看RabbitMQ消息内容?

java - 当消息因队列大小而被拒绝时,RabbitMQ 不会导致发送失败

javascript - Node JS - 文件生成器架构

java - Spring Integration 和 RabbitMQ,如何避免对入站 channel 适配器进行轮询