go的RabbitMQ中 Delivery.Ack 和 Channel.Ack 有什么区别 ?

在RabbitMQ的go支持库中,有两个方法
func (ch *Channel) Ack(tag uint64, multiple bool) errorfunc (d Delivery) Ack(multiple bool) error
但不明白这两个方法有什么区别?
两个方法的说明如下:

Channel.Ack

Ack acknowledges a delivery by its delivery tag when having been consumed with Channel.Consume or Channel.Get.

Ack acknowledges all message received prior to the delivery tag when multiple is true.

See also Delivery.Ack

Delivery.Ack

Ack delegates an acknowledgement through the Acknowledger interface that the client or server has finished work on a delivery.

All deliveries in AMQP must be acknowledged. If you called Channel.Consume with autoAck true then the server will be automatically ack each message and this method should not be called. Otherwise, you must call Delivery.Ack after you have successfully processed this delivery.

When multiple is true, this delivery and all prior unacknowledged deliveries on the same channel will be acknowledged. This is useful for batch processing of deliveries.

An error will indicate that the acknowledge could not be delivered to the channel it was sent from.

Either Delivery.Ack, Delivery.Reject or Delivery.Nack must be called for every delivery that is not automatically acknowledged.

AMQP库说明

阅读 4.7k
1 个回答
✓ 已被采纳新手上路,请多包涵

AMQP库中有三个Ack

  1. Acknowledger.Ack
  2. Channel.Ack
  3. Delivery.Ack

看了源码,发现Acknowledger是一个接口,里面有三个方法Ack,Nack,Reject,而Channel实现了这个接口
Delivery里面有一个成员变量是Acknowledger类型的,所以Delivery也可以调用该方法

所以:

  • Acknowledger是接口
  • Channel是具体实现
  • Delivery是具体实例(对象)
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题