Skip to content

Instantly share code, notes, and snippets.

@javier
Last active April 19, 2018 10:49
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 javier/d4e622dcc5986457e6ed7665842be276 to your computer and use it in GitHub Desktop.
Save javier/d4e622dcc5986457e6ed7665842be276 to your computer and use it in GitHub Desktop.
Pub Sub Quick demo for pulling
sudo pip install --upgrade google-cloud-pubsub
gcloud pubsub topics create cp300
gcloud pubsub subscriptions create cpsubs --topic=cp300
python
#that's it.. now just copy the contents of the python file
from google.cloud import pubsub_v1
subscriber = pubsub_v1.SubscriberClient()
def callback(message):
print('Received message: {}'.format(message))
message.ack()
#make sure you replace "javier" with your project name
subscription_path = 'projects/javier/subscriptions/cpsubs'
subscriber.subscribe(subscription_path, callback=callback)
#just go to https://console.cloud.google.com/cloudpubsub/subscriptions/cpsubs
#and publish some messages. You will see the payload inmediately on cloudshell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment