@@ -70,7 +70,7 @@ class Message(object):
7070 published.
7171 """
7272
73- def __init__ (self , message , ack_id , request_queue ):
73+ def __init__ (self , message , ack_id , delivery_attempt , request_queue ):
7474 """Construct the Message.
7575
7676 .. note::
@@ -82,12 +82,16 @@ def __init__(self, message, ack_id, request_queue):
8282 message (~.pubsub_v1.types.PubsubMessage): The message received
8383 from Pub/Sub.
8484 ack_id (str): The ack_id received from Pub/Sub.
85+ delivery_attempt (int): The delivery attempt counter received
86+ from Pub/Sub if a DeadLetterPolicy is set on the subscription,
87+ and zero otherwise.
8588 request_queue (queue.Queue): A queue provided by the policy that
8689 can accept requests; the policy is responsible for handling
8790 those requests.
8891 """
8992 self ._message = message
9093 self ._ack_id = ack_id
94+ self ._delivery_attempt = delivery_attempt if delivery_attempt > 0 else None
9195 self ._request_queue = request_queue
9296 self .message_id = message .message_id
9397
@@ -162,6 +166,30 @@ def ack_id(self):
162166 """str: the ID used to ack the message."""
163167 return self ._ack_id
164168
169+ @property
170+ def delivery_attempt (self ):
171+ """The delivery attempt counter is 1 + (the sum of number of NACKs
172+ and number of ack_deadline exceeds) for this message. It is set to None
173+ if a DeadLetterPolicy is not set on the subscription.
174+
175+ A NACK is any call to ModifyAckDeadline with a 0 deadline. An ack_deadline
176+ exceeds event is whenever a message is not acknowledged within
177+ ack_deadline. Note that ack_deadline is initially
178+ Subscription.ackDeadlineSeconds, but may get extended automatically by
179+ the client library.
180+
181+ The first delivery of a given message will have this value as 1. The value
182+ is calculated at best effort and is approximate.
183+
184+ EXPERIMENTAL: This feature is part of a closed alpha release. This
185+ API might be changed in backward-incompatible ways and is not recommended
186+ for production use. It is not subject to any SLA or deprecation policy.
187+
188+ Returns:
189+ Optional[int]: The delivery attempt counter or None.
190+ """
191+ return self ._delivery_attempt
192+
165193 def ack (self ):
166194 """Acknowledge the given message.
167195
0 commit comments