Skip to content
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
38 changes: 38 additions & 0 deletions pubsub/cloud-client/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,35 @@ def delete_subscription(project, subscription_name):
print('Subscription deleted: {}'.format(subscription_path))


def update_subscription(project, subscription_name, ack_deadline_seconds):
"""
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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the fields that are mutable and non mutable documented anywhere?

"""
subscriber = pubsub_v1.SubscriberClient()
subscription_path = subscriber.subscription_path(
project, subscription_name)

subscription = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the other samples we actually use the real types over dictionaries, so maybe make this subscription = pubsub_v1.types.Subscription(name=..., ack_deadline_seconds=...)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

'name': subscription_path,
'ack_deadline_seconds': ack_deadline_seconds,
}

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

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))


def receive_messages(project, subscription_name):
"""Receives messages from a pull subscription."""
subscriber = pubsub_v1.SubscriberClient()
Expand Down Expand Up @@ -179,10 +208,16 @@ def callback(message):
create_push_parser.add_argument('subscription_name')
create_push_parser.add_argument('endpoint')


delete_parser = subparsers.add_parser(
'delete', help=delete_subscription.__doc__)
delete_parser.add_argument('subscription_name')

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)

receive_parser = subparsers.add_parser(
'receive', help=receive_messages.__doc__)
receive_parser.add_argument('subscription_name')
Expand Down Expand Up @@ -214,6 +249,9 @@ def callback(message):
elif args.command == 'delete':
delete_subscription(
args.project, args.subscription_name)
elif args.command == 'update':
update_subscription(
args.project, args.subscription_name, args.ack_deadline_seconds)
elif args.command == 'receive':
receive_messages(args.project, args.subscription_name)
elif args.command == 'receive-flow-control':
Expand Down