Bird
0
0

Given this Python snippet, what will be the output if the publish call succeeds?

medium📝 Predict Output Q4 of 15
GCP - Cloud Pub/Sub
Given this Python snippet, what will be the output if the publish call succeeds?
from google.cloud import pubsub_v1
publisher = pubsub_v1.PublisherClient()
topic_path = 'projects/my-project/topics/my-topic'
future = publisher.publish(topic_path, b'Hello')
print(future.result())
AThe original message content 'Hello'
BThe message ID string of the published message
CAn error message about missing credentials
DNone, because publish() returns nothing
Step-by-Step Solution
Solution:
  1. Step 1: Understand what publish() returns

    publish() returns a Future object representing the asynchronous publish operation.
  2. Step 2: Calling future.result() waits and returns the message ID

    When the publish completes, future.result() returns the message ID string.
  3. Final Answer:

    The message ID string of the published message -> Option B
  4. Quick Check:

    future.result() = message ID string [OK]
Quick Trick: future.result() returns message ID after publish [OK]
Common Mistakes:
  • Expecting original message content
  • Assuming publish returns None
  • Ignoring asynchronous nature

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GCP Quizzes