Skip to content

Instantly share code, notes, and snippets.

@goungoun
Created May 5, 2018 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goungoun/6f593f866fbf73ab2f99ac24cf93e37e to your computer and use it in GitHub Desktop.
Save goungoun/6f593f866fbf73ab2f99ac24cf93e37e to your computer and use it in GitHub Desktop.
# gcloud beta pubsub topics create sanidego
# gcloud beta pubsub topics publish sandiego "hello"
from google.cloud import pubsub
client = pubsub.Client()
topic = client.topic("sandiego")
topic.create()
topic.publish(b'hello')
@goungoun
Copy link
Author

goungoun commented May 5, 2018

Publish a single message to a topic, with attributes

topic.publish(b'Another message payload', extra='EXTRA')

Publish a set of message to a topic (as a single request):

with topic.batch() as batch:
batch.publish(PAYLOAD1)
batch.publiish(PAYLOAD2, extra=EXTRA)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment