Bird
0
0

Consider this code snippet using Google Cloud Pub/Sub subscriber client:

medium📝 service behavior Q13 of 15
GCP - Cloud Pub/Sub
Consider this code snippet using Google Cloud Pub/Sub subscriber client:
def callback(message):
    print(f"Received: {message.data.decode('utf-8')}")
    # No acknowledgment called here

subscriber.subscribe(subscription_path, callback=callback)
What will happen to the messages if the callback never calls message.ack()?
AMessages will be acknowledged automatically after printing.
BMessages will be lost immediately after printing.
CMessages will be redelivered until acknowledged or retention expires.
DMessages will be sent to a dead-letter topic instantly.
Step-by-Step Solution
Solution:
  1. Step 1: Understand callback behavior without ack

    If message.ack() is not called, Pub/Sub considers the message unacknowledged.
  2. Step 2: Effect on message delivery

    Unacknowledged messages are redelivered repeatedly until acknowledged or retention period expires.
  3. Final Answer:

    Messages will be redelivered until acknowledged or retention expires. -> Option C
  4. Quick Check:

    No ack means redelivery until retention ends [OK]
Quick Trick: No ack means message redelivery until retention ends [OK]
Common Mistakes:
  • Assuming messages auto-acknowledge after callback
  • Thinking messages are lost immediately without ack
  • Believing messages go to dead-letter topic without config

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GCP Quizzes