Last active
April 19, 2018 10:49
-
-
Save javier/d4e622dcc5986457e6ed7665842be276 to your computer and use it in GitHub Desktop.
Pub Sub Quick demo for pulling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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