-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Add sample for updating a subscription. #1335
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
| """ | ||
| subscriber = pubsub_v1.SubscriberClient() | ||
| subscription_path = subscriber.subscription_path( | ||
| project, subscription_name) | ||
|
|
||
| subscription = { | ||
|
||
| '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() | ||
|
|
@@ -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') | ||
|
|
@@ -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': | ||
|
|
||
There was a problem hiding this comment.
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?