Complete the code to set the acknowledgment deadline for a Pub/Sub subscription.
subscription = pubsub_client.subscription('projects/my-project/subscriptions/my-subscription') subscription.modify_ack_deadline(seconds=[1])
The acknowledgment deadline is set in seconds. 60 seconds is a common default to allow enough time for message processing before redelivery.
Complete the code to acknowledge a received message in Pub/Sub.
def callback(message): print(f'Received message: {message.data}') message.[1]()
Calling ack() on the message tells Pub/Sub that the message was processed successfully and should not be redelivered.
Fix the error in the code to extend the acknowledgment deadline for a message.
def callback(message): # Extend ack deadline by 30 seconds message.modify_ack_deadline(seconds=[1]) message.ack()
The modify_ack_deadline method extends the deadline by the given seconds. 30 seconds is a typical extension time.
Fill both blanks to create a subscription with a message retention duration and enable message ordering.
subscription = pubsub_client.create_subscription(
name='projects/my-project/subscriptions/my-subscription',
topic='projects/my-project/topics/my-topic',
message_retention_duration=[1],
enable_message_ordering=[2]
)The message retention duration is set in seconds as a string with 's' suffix. '604800s' equals 7 days. Enabling message ordering requires setting enable_message_ordering to True.
Fill all three blanks to create a pull subscription with a custom acknowledgment deadline and enable exactly-once delivery.
subscription = pubsub_client.create_subscription(
name='projects/my-project/subscriptions/my-subscription',
topic='projects/my-project/topics/my-topic',
ack_deadline_seconds=[1],
enable_exactly_once_delivery=[2],
retain_acked_messages=[3]
)The acknowledgment deadline is set to 10 seconds. Exactly-once delivery and retaining acknowledged messages are enabled by setting their flags to True.