Consumer Acknowledgements and Publisher Confirms

翻译 2018年04月17日 19:38:01

点击打开链接


Acknowledging Multiple Deliveries at Once

Manual acknowledgements can be batched to reduce network traffic. This is done by setting the multiple field of acknowledgement methods (see above) to true. Note that basic.rejectdoesn't historically have the field and that's why basic.nack was introduced by RabbitMQ as a protocol extension.

When the multiple field is set to true, RabbitMQ will acknowledge all outstanding delivery tags up to and including the tag specified in the acknowledgement. Like everything else related to acknowledgements, this is scoped per channel. For example, given that there are delivery tags 5, 6, 7, and 8 unacknowledged on channel Ch, when an acknowledgement frame arrives on that channel with delivery_tag set to 8 and multiple set to true, all tags from 5 to 8 will be acknowledged. If multiple was set to false, deliveries 5, 6, and 7 would still be unacknowledged.


Channel Prefetch Setting (QoS)

Because messages are sent (pushed) to clients asynchronously, there is usually more than one message "in flight" on a channel at any given moment. In addition, manual acknowledgements from clients are also inherently asynchronous in nature. So there's a sliding window of delivery tags that are unacknowledged. Developers would often prefer to cap the size of this window to avoid the unbounded buffer problem on the consumer end. This is done by setting a "prefetch count" value using the basic.qos method. The value defines the max number of unacknowledged deliveries that are permitted on a channel. Once the number reaches the configured count, RabbitMQ will stop delivering more messages on the channel unless at least one of the outstanding ones is acknowledged.

For example, given that there are delivery tags 5, 6, 7, and 8 unacknowledged on channel Chand channel Ch's prefetch count is set to 4, RabbitMQ will not push any more deliveries on Chunless at least one of the outstanding deliveries is acknowledged. When an acknowledgement frame arrives on that channel with delivery_tag set to 8, RabbitMQ will notice and deliver one more message.

Consumer Acknowledgement Modes, Prefetch and Throughput

Acknowledgement mode and QoS prefetch value have significant effect on consumer throughput. In general, increasing prefetch will improve the rate of message delivery to consumers. Automatic acknowledgement mode yields best possible rate of delivery. However, in both cases the number of delivered but not-yet-processed messages will also increase, thus increasing consumer RAM consumption.

Automatic acknowledgement mode or manual acknowledgement mode with unlimited prefetch should be used with care. Consumers that consume a lot of messages without acknowledging will lead to memory consumption growth on the node they are connected to. 

Publisher Confirms

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. In this case, transactions are unnecessarily heavyweight and decrease throughput by a factor of 250. To remedy this, a confirmation mechanism was introduced. It mimics the consumer acknowledgements mechanism already present in the protocol.

To enable confirms, a client sends the confirm.select method. Depending on whether no-waitwas set or not, the broker may respond with a confirm.select-ok. Once the confirm.selectmethod is used on a channel, it is said to be in confirm mode. A transactional channel cannot be put into confirm mode and once a channel is in confirm mode, it cannot be made transactional.

Once a channel is in confirm mode, both the broker and the client count messages (counting starts at 1 on the first confirm.select). The broker then confirms messages as it handles them by sending a basic.ack on the same channel. The delivery-tag field contains the sequence number of the confirmed message. The broker may also set the multiple field in basic.ack to indicate that all messages up to and including the one with the sequence number have been handled.

Ack Latency for Persistent Messages

basic.ack for a persistent message routed to a durable queue will be sent after persisting the message to disk. The RabbitMQ message store persists messages to disk in batches after an interval (a few hundred milliseconds) to minimise the number of fsync(2) calls, or when a queue is idle. This means that under a constant load, latency for basic.ack can reach a few hundred milliseconds. To improve throughput, applications are strongly advised to process acknowledgements asynchronously (as a stream) or publish batches of messages and wait for outstanding confirms.


RabbitMQ 之 Publisher Acknowledgement(翻译)

rabbitmq confirm
  • longxibendi
  • longxibendi
  • 2016-01-22 17:24:16
  • 943

Spring AMQP - Publisher Confirms解决MQ丢消息

事务(Transactional)或发布确认(Publisher Confirms / aka Publisher Acknowledgements)机制可保证消息被正确投递,即从理论上来说MQ不会丢...
  • ujsleo
  • ujsleo
  • 2017-03-23 16:48:22
  • 2293

RabbitMQ消息队列(九):Publisher的消息确认机制

有没有一种机制能保证Publisher能够感知它的Message有没有被处理的?答案肯定的。 唯一能够保证消息不会丢失的方式是利用事务机制 -- 令 channel 处于 transactional ...
  • anzhsoft2008
  • anzhsoft2008
  • 2014-03-20 13:28:38
  • 47371

rabbitMq生产者角度:消息持久化、事务机制、PublisherConfirm、mandatory

一、消息持久化
  • u014045580
  • u014045580
  • 2017-04-21 10:28:54
  • 782

rabbitMQ配置spring boot

package rabbitmq.config; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org....
  • Ajax2Json
  • Ajax2Json
  • 2017-10-29 23:55:54
  • 86

rabbitMQ confirm

如果采用标准的 AMQP 协议,则唯一能够保证消息不会丢失的方式是利用事务机制 -- 令 channel 处于 transactional 模式、向其 publish 消息、执行 commit 动作。...
  • h70614959
  • h70614959
  • 2013-12-11 12:15:57
  • 4909

ActiveMq-Publisher/Subscribe入门例子

启动ActiveMq、添加依赖与之前完全相同,此处省略 1.发布端 import javax.jms.Connection; import javax.jms.ConnectionFactory;...
  • cpf2016
  • cpf2016
  • 2015-06-14 15:06:50
  • 527

RabbitMQ(一)publish消息确认

Confirms (aka Publisher Acknowledgements) Using standard AMQP, the only way to guarantee that a me...
  • xtjsxtj
  • xtjsxtj
  • 2014-03-20 09:23:19
  • 15554

从零开始的RxJava2.0教程(一)基础

1. 为什么写这篇文章RxJava这些年越来越流行,而上月末(2016.10.29)发布了2.0正式版,但网上大部分关于RxJava的教程都是1.x的。关于2.0的教程基本是介绍1.x和2.x的区别,...
  • qq_35064774
  • qq_35064774
  • 2016-11-06 22:43:50
  • 21703

latex 论文致谢

1.  To add a non numbered section you just use \section*{Acknowledgement} If you want to insert t...
  • solidsanke54
  • solidsanke54
  • 2015-10-28 10:59:48
  • 2589
收藏助手
不良信息举报
您举报文章:Consumer Acknowledgements and Publisher Confirms
举报原因:
原因补充:

(最多只允许输入30个字)