在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java  GO/ go的RabbitMQ中 Delivery.Ack 和 Channel.Ack

go的RabbitMQ中 Delivery.Ack 和 Channel.Ack 有什么區(qū)別 ?

在RabbitMQ的go支持庫中,有兩個方法
func (ch *Channel) Ack(tag uint64, multiple bool) errorfunc (d Delivery) Ack(multiple bool) error
但不明白這兩個方法有什么區(qū)別?
兩個方法的說明如下:

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庫說明

回答
編輯回答
熊出沒

AMQP庫中有三個Ack

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

看了源碼,發(fā)現(xiàn)Acknowledger是一個接口,里面有三個方法Ack,Nack,Reject,而Channel實現(xiàn)了這個接口
Delivery里面有一個成員變量是Acknowledger類型的,所以Delivery也可以調(diào)用該方法

所以:

  • Acknowledger是接口
  • Channel是具體實現(xiàn)
  • Delivery是具體實例(對象)
2017年12月16日 03:37