rabbitmq - Why message can be lost when rabbitmq basic.publish return ok
问题描述
From the Rabbitmq doc
Networks can fail in less-than-obvious ways and detecting some failures takes time. Therefore a client that's written a protocol frame or a set of frames (e.g. a published message) to its socket cannot assume that the message has reached the server and was successfully processed. It could have been lost along the way or its delivery can be significantly delayed.
Using standard AMQP 0-9-1, the only way to guarantee that a message isn't lost is by using transactions -- make the channel transactional then for each message or set of messages publish, commit.
I wonder why the publish-confirm or transaction is required to prevent the message lost for producer publish.
If the amqp "basic.publish" is called successful, the api return ok, why the message still possible lost?
解决方案
该片段正在谈论 AMQP 0-9-1。RabbitMQ 提供了对该协议的扩展,其中之一是 Publisher Confirms。发布者确认不是 AMQP 0-9-1 标准本身的一部分。
如果您收到“OK”或 basic.ack,那么这就是发布者确认。一旦你收到了那个 bacic.ack 就意味着代理肯定收到了消息。但是此时您仍然可能“丢失”消息。如果没有绑定到该交换的队列或没有具有与消息匹配的绑定的队列,则代理将丢弃该消息。因此,尽管您收到了 basic.ack,但该消息现在已丢失。
因此,如果您真的想要一些保证,您应该使用 Publisher Confirms 并在消息上设置 Mandatory 标志。如果您使用此标志,那么如果代理收到消息但无法将其路由到交换,您将收到来自代理的 basic.return(后跟 basic.ack)响应。然后,您的应用程序可以采取适当的措施。
推荐阅读
- ruby-on-rails - 如何根据用户输入打印数组中的相关索引号
- docker - 安排 docker-compose 启动顺序
- reactjs - Reactjs:显示编辑表单onClick
- ruby - 如何使用 find 修复 Document Not Found 错误
- php - 如何开始循环遍历不同索引处的数组并完成整个数组
- html - 当视口宽度变小时,标题中的所有内容都会变小。我该如何改变?
- c++ - C++ 语言定义对 static 关键字的范围有什么看法?
- scala - 无法将火花数据框保存为 CSV
- python - 使用 tflearn、tensorflow、numpy 的 Python 聊天机器人出错
- java - org.springframework.batch.core.JobExecutionException:分区处理程序返回一个不成功的步骤