Skip to content

Commit

Permalink
Change update_subscription to change endpoint URL. [(#1344)](GoogleCl…
Browse files Browse the repository at this point in the history
…oudPlatform/python-docs-samples#1344)

The documentation specifies that the update subscription commands show how to update an endpoint URL: https://cloud.google.com/pubsub/docs/admin#update_a_subscription.
  • Loading branch information
noerog authored and plamut committed Jul 10, 2020
1 parent 4794aca commit 88adfac
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions samples/snippets/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def create_push_subscription(project,
topic_name,
subscription_name,
endpoint):
"""Create a new push subscription on the given topic."""
"""Create a new push subscription on the given topic.
For example, endpoint is
"https://my-test-project.appspot.com/push".
"""
subscriber = pubsub_v1.SubscriberClient()
topic_path = subscriber.topic_path(project, topic_name)
subscription_path = subscriber.subscription_path(
Expand All @@ -89,32 +92,36 @@ def delete_subscription(project, subscription_name):
print('Subscription deleted: {}'.format(subscription_path))


def update_subscription(project, subscription_name, ack_deadline_seconds):
def update_subscription(project, subscription_name, endpoint):
"""
Updates an existing Pub/Sub subscription's ackDeadlineSeconds
from 10 seconds (default). Note that certain properties of a
subscription, such as its topic, are not modifiable.
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".
"""
subscriber = pubsub_v1.SubscriberClient()
subscription_path = subscriber.subscription_path(
project, subscription_name)

push_config = pubsub_v1.types.PushConfig(
push_endpoint=endpoint)

subscription = pubsub_v1.types.Subscription(
name=subscription_path,
ack_deadline_seconds=ack_deadline_seconds)
push_config=push_config)

update_mask = {
'paths': {
'ack_deadline_seconds',
'push_config',
}
}

subscriber.update_subscription(subscription, update_mask)
result = subscriber.get_subscription(subscription_path)

print('Subscription updated: {}'.format(subscription_path))
print('New ack_deadline_seconds value is: {}'.format(
result.ack_deadline_seconds))
print('New endpoint for subscription is: {}'.format(
result.push_config))


def receive_messages(project, subscription_name):
Expand Down Expand Up @@ -214,7 +221,7 @@ def callback(message):
update_parser = subparsers.add_parser(
'update', help=update_subscription.__doc__)
update_parser.add_argument('subscription_name')
update_parser.add_argument('ack_deadline_seconds', type=int)
update_parser.add_argument('endpoint')

receive_parser = subparsers.add_parser(
'receive', help=receive_messages.__doc__)
Expand Down Expand Up @@ -249,7 +256,7 @@ def callback(message):
args.project, args.subscription_name)
elif args.command == 'update':
update_subscription(
args.project, args.subscription_name, args.ack_deadline_seconds)
args.project, args.subscription_name, args.endpoint)
elif args.command == 'receive':
receive_messages(args.project, args.subscription_name)
elif args.command == 'receive-flow-control':
Expand Down

0 comments on commit 88adfac

Please sign in to comment.