Skip to content

Commit

Permalink
Ensure that quickstart examples actually work. (#4398)
Browse files Browse the repository at this point in the history
Closes #4394.
  • Loading branch information
tseaver authored Nov 15, 2017
1 parent 5a0e549 commit 79a782f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pubsub/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ messages to it
from google.cloud import pubsub
publisher = pubsub.PublisherClient()
topic = 'projects/{project_id}/topics/{topic}'.format(
topic_name = 'projects/{project_id}/topics/{topic}'.format(
project_id=os.getenv('GOOGLE_CLOUD_PROJECT'),
topic='MY_TOPIC_NAME', # Set this to something appropriate.
)
publisher.create_topic()
publisher.publish(topic, b'My first message!', spam='eggs')
publisher.create_topic(topic_name)
publisher.publish(topic_name, b'My first message!', spam='eggs')
To learn more, consult the `publishing documentation`_.

Expand All @@ -90,15 +90,16 @@ the topic, and subscribe to that.
from google.cloud import pubsub
subscriber = pubsub.SubscriberClient()
topic = 'projects/{project_id}/topics/{topic}'.format(
topic_name = 'projects/{project_id}/topics/{topic}'.format(
project_id=os.getenv('GOOGLE_CLOUD_PROJECT'),
topic='MY_TOPIC_NAME', # Set this to something appropriate.
)
subscription_name = 'projects/{project_id}/subscriptions/{sub}'.format(
project_id=os.getenv('GOOGLE_CLOUD_PROJECT'),
sub='MY_SUBSCRIPTION_NAME', # Set this to something appropriate.
)
subscription = subscriber.create_subscription(topic, subscription)
subscription = subscriber.create_subscription(
name=subscription_name, topic=topic_name)
The subscription is opened asychronously, and messages are processed by
use of a callback.
Expand Down

0 comments on commit 79a782f

Please sign in to comment.