When a message is delivered to a pull subscriber, the subscriber must process and acknowledge (ack) the message within the acknowledgment deadline. Else, the subscriber must extend the deadline with a call to modify the acknowledgment deadline.
The Pub/Sub high-level client libraries provide lease management as a feature that automatically extends the deadline of a message that has not yet been acknowledged. By default, the client libraries can extend the deadline to an hour by issuing periodic modifyAckDeadline requests.The high-level client libraries for Python, Go, Java, and .Net use the 99th percentile of acknowledgment delay to determine the length of each extension.
Lease management lets you have more granular control over the acknowledgment deadline for messages compared to configuring the subscription-level property. If you're only using the subscription-level acknowledgment deadline, you have to balance the tradeoff between a low value and a high value. A low value increases the likelihood of duplicates and a high value delays the redelivery of failed messages. Determining the right value can be difficult, especially when the expected processing time for different messages varies greatly.
For more information about the properties of a subscription, including acknowledgment deadline, see Subscription properties.
Lease management configuration
You can configure the following properties in the high-level client libraries to control lease management.
Maximum acknowledgment extension period. The maximum amount of time for which you can extend the acknowledgment deadline of a message by using the
modify acknowledgment deadline
request. This property lets you determine how long you want the subscriber clients to process messages.Maximum duration for each acknowledgment extension. The maximum amount of time by which to extend the acknowledgment deadline for each of the
modify acknowledgment deadline
requests. This property lets you define the amount of time Pub/Sub takes to redeliver a message. Redelivery occurs when the first subscriber processing the message crashes or becomes unhealthy and is no longer able to send themodify acknowledgment deadline
request.Minimum duration for each acknowledgment extension. The minimum amount of time by which to extend the acknowledgment deadline for each of the
modify acknowledgment deadline
requests. This property lets you specify the minimum amount of time that must pass before the redelivery of a message occurs.
Acknowledgment deadlines are not guaranteed to be respected unless you enable exactly-once delivery.
Manually managing ack deadlines
To avoid expiration and redelivery of messages when using unary pull or the
low-level client libraries, use the modify acknowledgment deadline
request to extend their acknowledgement
deadlines. The exceptions are the Go and C++
high-level client libraries which provide lease management when using unary
pull. See the following samples for unary pull with lease management:
C#
Before trying this sample, follow the C# setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub C# API reference documentation.
Java
Before trying this sample, follow the Java setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub Java API reference documentation.
Node.js
Before trying this sample, follow the Node.js setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub Node.js API reference documentation.
Python
Before trying this sample, follow the Python setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub Python API reference documentation.
Ruby
Before trying this sample, follow the Ruby setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub Ruby API reference documentation.
What's next
Read about the other delivery options you can configure for a subscription: