Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update subscriber example in README to current patterns. #6194

Merged
merged 3 commits into from
Oct 12, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions pubsub/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Subscribing
^^^^^^^^^^^

To subscribe to data in Cloud Pub/Sub, you create a subscription based on
the topic, and subscribe to that.
the topic, and subscribe to that, passing a callback function.

.. code-block:: python

Expand All @@ -127,17 +127,22 @@ the topic, and subscribe to that.
)
subscriber.create_subscription(
name=subscription_name, topic=topic_name)
subscription = subscriber.subscribe(subscription_name)

The subscription is opened asychronously, and messages are processed by
use of a callback.

.. code-block:: python

def callback(message):
print(message.data)
message.ack()
subscription.open(callback)

future = subscriber.subscribe(subscription_name, callback)

The future returned by the call to ``subscriber.subscribe`` can be used to
block the current thread until a given condition obtains:

.. code-block:: python

try:
future.result()
except KeyboardInterrupt:
future.cancel()

To learn more, consult the `subscriber documentation`_.

Expand Down