Bird
0
0

A developer wrote this code snippet to acknowledge messages but messages keep getting redelivered. What is the likely error?

medium📝 Debug Q6 of 15
GCP - Cloud Pub/Sub
A developer wrote this code snippet to acknowledge messages but messages keep getting redelivered. What is the likely error?
def callback(message):
    print(message.data)
    # missing acknowledgment call
AThe client library is outdated
BThe subscription does not exist
CThe message data is empty
DThe callback function does not call message.ack()
Step-by-Step Solution
Solution:
  1. Step 1: Analyze callback function

    The callback prints message data but does not acknowledge the message.
  2. Step 2: Understand consequence of missing ack

    Without calling message.ack(), Pub/Sub assumes message was not processed and redelivers it.
  3. Final Answer:

    The callback function does not call message.ack() -> Option D
  4. Quick Check:

    Missing message.ack() causes redelivery [OK]
Quick Trick: Always call message.ack() in callback to stop redelivery [OK]
Common Mistakes:
  • Forgetting to call message.ack()
  • Assuming print is enough
  • Blaming subscription or client library

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GCP Quizzes