From e5177fab060b8d229b59def31cf4c94a847eb791 Mon Sep 17 00:00:00 2001 From: Carlos de la Guardia Date: Mon, 21 Sep 2020 03:13:43 -0500 Subject: [PATCH 1/2] docs: use new call syntax in subscriber docs Refs #198 --- docs/subscriber/index.rst | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/docs/subscriber/index.rst b/docs/subscriber/index.rst index ed99566cd..8bcad2742 100644 --- a/docs/subscriber/index.rst +++ b/docs/subscriber/index.rst @@ -38,7 +38,7 @@ to subscribe to, and it must already exist. Once you have that, it is easy: # your application. sub_path = subscriber.subscription_path(PROJECT, SUBSCRIPTION) topic_path = subscriber.topic_path(PROJECT, TOPIC) - subscriber.create_subscription(sub_path, topic_path) + subscriber.create_subscription(request = {'name': sub_path, 'topic': topic_path}) Once you have created a subscription (or if you already had one), the next step is to pull data from it. @@ -55,13 +55,23 @@ To pull the messages synchronously, use the client's # Substitute PROJECT and SUBSCRIPTION with appropriate values for your # application. subscription_path = subscriber.subscription_path(PROJECT, SUBSCRIPTION) - response = subscriber.pull(subscription_path, max_messages=5) + response = subscriber.pull( + request = { + 'subscription': subscription_path, + 'max_messages': 5, + } + ) for msg in response.received_messages: print("Received message:", msg.message.data) ack_ids = [msg.ack_id for msg in response.received_messages] - subscriber.acknowledge(subscription_path, ack_ids) + subscriber.acknowledge( + request = { + 'subscription': subscription_path, + 'ack_ids': ack_ids, + } + ) The method returns a :class:`~.pubsub_v1.types.PullResponse` instance that contains a list of received :class:`~.pubsub_v1.types.ReceivedMessage` @@ -76,7 +86,13 @@ be dropped by this client and the backend will try to re-deliver them. ack_ids = [] # TODO: populate with `ack_ids` of the messages to NACK ack_deadline_seconds = 0 - subscriber.modify_ack_deadline(subscription_path, ack_ids, ack_deadline_seconds) + subscriber.modify_ack_deadline( + request = {] + 'subscription': subscription_path, + 'ack_ids': ack_ids, + 'ack_deadline_seconds': ack_deadline_seconds, + } + ) Pulling a Subscription Asynchronously From 6dd8925794110112050fc6571fee3034a58716b1 Mon Sep 17 00:00:00 2001 From: Carlos de la Guardia Date: Mon, 21 Sep 2020 03:50:47 -0500 Subject: [PATCH 2/2] fix typo, use double quotes --- docs/subscriber/index.rst | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/subscriber/index.rst b/docs/subscriber/index.rst index 8bcad2742..bfd2fff26 100644 --- a/docs/subscriber/index.rst +++ b/docs/subscriber/index.rst @@ -38,7 +38,7 @@ to subscribe to, and it must already exist. Once you have that, it is easy: # your application. sub_path = subscriber.subscription_path(PROJECT, SUBSCRIPTION) topic_path = subscriber.topic_path(PROJECT, TOPIC) - subscriber.create_subscription(request = {'name': sub_path, 'topic': topic_path}) + subscriber.create_subscription(request={"name": sub_path, "topic": topic_path}) Once you have created a subscription (or if you already had one), the next step is to pull data from it. @@ -56,9 +56,9 @@ To pull the messages synchronously, use the client's # application. subscription_path = subscriber.subscription_path(PROJECT, SUBSCRIPTION) response = subscriber.pull( - request = { - 'subscription': subscription_path, - 'max_messages': 5, + request={ + "subscription": subscription_path, + "max_messages": 5, } ) @@ -67,9 +67,9 @@ To pull the messages synchronously, use the client's ack_ids = [msg.ack_id for msg in response.received_messages] subscriber.acknowledge( - request = { - 'subscription': subscription_path, - 'ack_ids': ack_ids, + request={ + "subscription": subscription_path, + "ack_ids": ack_ids, } ) @@ -87,10 +87,10 @@ be dropped by this client and the backend will try to re-deliver them. ack_ids = [] # TODO: populate with `ack_ids` of the messages to NACK ack_deadline_seconds = 0 subscriber.modify_ack_deadline( - request = {] - 'subscription': subscription_path, - 'ack_ids': ack_ids, - 'ack_deadline_seconds': ack_deadline_seconds, + request={ + "subscription": subscription_path, + "ack_ids": ack_ids, + "ack_deadline_seconds": ack_deadline_seconds, } )