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.
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 on the properties of a subscription, including acknowledgment deadline, see Subscription properties.
For more information about the message-specific modify acknowledgment deadline, see the REST API Method: projects.subscriptions.modifyAckDeadline.
Lease management configuration
You can use the modify acknowledgment deadline
request to configure
the following properties. In the Java client library this variable is
represented by ModifyAckDeadlineRequest()
.
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.
Code samples for manually managing ack deadlines
To avoid redelivery on expired messages, the client libraries provide a way to reset their acknowledgement deadlines. The exceptions are the Go and C++ high-level client libraries which automatically modify the acknowledgement deadlines for polled messages. See the following samples for synchronous pull mode 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: