Bird
0
0

Which Python code snippet correctly publishes a message to a Google Cloud Pub/Sub topic using the client library?

easy📝 Syntax Q3 of 15
GCP - Cloud Pub/Sub
Which Python code snippet correctly publishes a message to a Google Cloud Pub/Sub topic using the client library?
Apublisher.send(topic_path, b'My message')
Bpublisher.publish(topic_path, 'My message')
Cpublisher.publish(topic_path, b'My message')
Dpublisher.send(topic_path, 'My message')
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct method

    The method to publish is 'publish', not 'send'.
  2. Step 2: Message format

    Messages must be bytes, so prefix string with b''.
  3. Final Answer:

    publisher.publish(topic_path, b'My message') -> Option C
  4. Quick Check:

    Use publish() with bytes message [OK]
Quick Trick: Use publish() method with bytes message [OK]
Common Mistakes:
  • Using 'send' instead of 'publish'
  • Passing string instead of bytes
  • Omitting the b'' prefix for bytes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GCP Quizzes