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

Pub/Sub: remove publish concurrency control sample #2960

Merged
merged 2 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
36 changes: 19 additions & 17 deletions pubsub/cloud-client/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
busunkim96 marked this conversation as resolved.
Show resolved Hide resolved
listen_for_errors Receives messages and catches errors from a pull
subscription.

Expand Down Expand Up @@ -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
Expand Up @@ -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."""
Expand Down Expand Up @@ -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__,
Expand Down Expand Up @@ -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":
Expand Down
7 changes: 0 additions & 7 deletions pubsub/cloud-client/publisher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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