Skip to content

Commit

Permalink
remove publish concurrency control sample (#2960)
Browse files Browse the repository at this point in the history
anguillanneuf authored Feb 24, 2020

Verified

This commit was signed with the committer’s verified signature. The key has expired.
HighCrit HighCrit
1 parent 586e069 commit aa7859f
Showing 3 changed files with 19 additions and 55 deletions.
36 changes: 19 additions & 17 deletions pubsub/cloud-client/README.rst
Original file line number Diff line number Diff line change
@@ -93,8 +93,8 @@ To run this sample:
$ python publisher.py
usage: publisher.py [-h]
project
{list,create,delete,publish,publish-with-custom-attributes,publish-with-futures,publish-with-batch-settings}
project_id
{list,create,delete,publish,publish-with-custom-attributes,publish-with-error-handler,publish-with-batch-settings,publish-with-retry-settings}
...
This application demonstrates how to perform basic operations on topics
@@ -104,21 +104,23 @@ To run this sample:
at https://cloud.google.com/pubsub/docs.
positional arguments:
project Your Google Cloud project ID
{list,create,delete,publish,publish-with-custom-attributes,publish-with-futures,publish-with-batch-settings}
project_id Your Google Cloud project ID
{list,create,delete,publish,publish-with-custom-attributes,publish-with-error-handler,publish-with-batch-settings,publish-with-retry-settings}
list Lists all Pub/Sub topics in the given project.
create Create a new Pub/Sub topic.
delete Deletes an existing Pub/Sub topic.
publish Publishes multiple messages to a Pub/Sub topic.
publish-with-custom-attributes
Publishes multiple messages with custom attributes to
a Pub/Sub topic.
publish-with-futures
Publishes multiple messages to a Pub/Sub topic and
prints their message IDs.
publish-with-error-handler
Publishes multiple messages to a Pub/Sub topic with an
error handler.
publish-with-batch-settings
Publishes multiple messages to a Pub/Sub topic with
batch settings.
publish-with-retry-settings
Publishes messages with custom retry settings.
optional arguments:
-h, --help show this help message and exit
@@ -141,8 +143,8 @@ To run this sample:
$ python subscriber.py
usage: subscriber.py [-h]
project
{list_in_topic,list_in_project,create,create-push,delete,update,receive,receive-custom-attributes,receive-flow-control,listen_for_errors}
project_id
{list_in_topic,list_in_project,create,create-push,delete,update,receive,receive-custom-attributes,receive-flow-control,receive-synchronously,receive-synchronously-with-lease,listen_for_errors}
...
This application demonstrates how to perform basic operations on
@@ -152,26 +154,26 @@ To run this sample:
at https://cloud.google.com/pubsub/docs.
positional arguments:
project Your Google Cloud project ID
{list_in_topic,list_in_project,create,create-push,delete,update,receive,receive-custom-attributes,receive-flow-control,listen_for_errors}
project_id Your Google Cloud project ID
{list_in_topic,list_in_project,create,create-push,delete,update,receive,receive-custom-attributes,receive-flow-control,receive-synchronously,receive-synchronously-with-lease,listen_for_errors}
list_in_topic Lists all subscriptions for a given topic.
list_in_project Lists all subscriptions in the current project.
create Create a new pull subscription on the given topic.
create-push Create a new push subscription on the given topic. For
example, endpoint is "https://my-test-
project.appspot.com/push".
create-push Create a new push subscription on the given topic.
delete Deletes an existing Pub/Sub topic.
update Updates an existing Pub/Sub subscription's push
endpoint URL. Note that certain properties of a
subscription, such as its topic, are not modifiable.
For example, endpoint is "https://my-test-
project.appspot.com/push".
receive Receives messages from a pull subscription.
receive-custom-attributes
Receives messages from a pull subscription.
receive-flow-control
Receives messages from a pull subscription with flow
control.
receive-synchronously
Pulling messages synchronously.
receive-synchronously-with-lease
Pulling messages synchronously with lease management
listen_for_errors Receives messages and catches errors from a pull
subscription.
@@ -244,4 +246,4 @@ to `browse the source`_ and `report issues`_.
https://github.com/GoogleCloudPlatform/google-cloud-python/issues
.. _Google Cloud SDK: https://cloud.google.com/sdk/
.. _Google Cloud SDK: https://cloud.google.com/sdk/
31 changes: 0 additions & 31 deletions pubsub/cloud-client/publisher.py
Original file line number Diff line number Diff line change
@@ -128,30 +128,6 @@ def publish_messages_with_custom_attributes(project_id, topic_name):
# [END pubsub_publish_custom_attributes]


def publish_messages_with_futures(project_id, topic_name):
"""Publishes multiple messages to a Pub/Sub topic and prints their
message IDs."""
# [START pubsub_publisher_concurrency_control]
from google.cloud import pubsub_v1

# TODO project_id = "Your Google Cloud Project ID"
# TODO topic_name = "Your Pub/Sub topic name"

publisher = pubsub_v1.PublisherClient()
topic_path = publisher.topic_path(project_id, topic_name)

for n in range(1, 10):
data = u"Message number {}".format(n)
# Data must be a bytestring
data = data.encode("utf-8")
# When you publish a message, the client returns a future.
future = publisher.publish(topic_path, data=data)
print(future.result())

print("Published messages with futures.")
# [END pubsub_publisher_concurrency_control]


def publish_messages_with_error_handler(project_id, topic_name):
# [START pubsub_publish_messages_error_handler]
"""Publishes multiple messages to a Pub/Sub topic with an error handler."""
@@ -308,11 +284,6 @@ def publish_messages_with_retry_settings(project_id, topic_name):
)
publish_with_custom_attributes_parser.add_argument("topic_name")

publish_with_futures_parser = subparsers.add_parser(
"publish-with-futures", help=publish_messages_with_futures.__doc__
)
publish_with_futures_parser.add_argument("topic_name")

publish_with_error_handler_parser = subparsers.add_parser(
"publish-with-error-handler",
help=publish_messages_with_error_handler.__doc__,
@@ -345,8 +316,6 @@ def publish_messages_with_retry_settings(project_id, topic_name):
publish_messages_with_custom_attributes(
args.project_id, args.topic_name
)
elif args.command == "publish-with-futures":
publish_messages_with_futures(args.project_id, args.topic_name)
elif args.command == "publish-with-error-handler":
publish_messages_with_error_handler(args.project_id, args.topic_name)
elif args.command == "publish-with-batch-settings":
7 changes: 0 additions & 7 deletions pubsub/cloud-client/publisher_test.py
Original file line number Diff line number Diff line change
@@ -138,10 +138,3 @@ def test_publish_with_error_handler(topic_publish, capsys):

out, _ = capsys.readouterr()
assert "Published" in out


def test_publish_with_futures(topic_publish, capsys):
publisher.publish_messages_with_futures(PROJECT, TOPIC_PUBLISH)

out, _ = capsys.readouterr()
assert "Published" in out

0 comments on commit aa7859f

Please sign in to comment.