Bird
0
0

Consider this code snippet for a pull subscription client in Python using Google Cloud Pub/Sub:

medium📝 service behavior Q13 of 15
GCP - Cloud Pub/Sub
Consider this code snippet for a pull subscription client in Python using Google Cloud Pub/Sub:
from google.cloud import pubsub_v1
subscriber = pubsub_v1.SubscriberClient()
subscription_path = subscriber.subscription_path('my-project', 'my-sub')
response = subscriber.pull(subscription=subscription_path, max_messages=1)
print(len(response.received_messages))
What will this code print if there is exactly one message available in the subscription?
AError due to missing ack
B0
C1
DNone
Step-by-Step Solution
Solution:
  1. Step 1: Understand pull method behavior

    The pull method requests messages; if one message is available, it returns it in received_messages.
  2. Step 2: Check printed output

    len(response.received_messages) will be 1 because exactly one message is pulled.
  3. Final Answer:

    1 -> Option C
  4. Quick Check:

    One message pulled means length is 1 [OK]
Quick Trick: Pull returns messages list; length matches available messages [OK]
Common Mistakes:
  • Assuming pull returns zero without ack
  • Expecting error if ack is missing
  • Confusing pull with push subscription behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GCP Quizzes