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
feat: Add dead lettering max delivery attempts argument #236
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d8e9047
Add max_delivery_attempts input to subsciber.py
danavaziri-ga 911300e
Make max_delivery_attempts argument optional
danavaziri-ga 28569e5
Add max_delivery_attempts parameter to create and update subscription…
danavaziri-ga 5fb0431
Merge branch 'master' into patch-1
danavaziri-ga 7ad3b6a
Add constants and defaults for max_delivery_attempts argument
danavaziri-ga 332bcce
Fix comments related to added max_delivery_attempts parameter
danavaziri-ga 52db582
Fix typo in max_delivery_attempts comments
danavaziri-ga File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,8 @@ def create_subscription(project_id, topic_id, subscription_id): | |
|
||
|
||
def create_subscription_with_dead_letter_topic( | ||
project_id, topic_id, subscription_id, dead_letter_topic_id | ||
project_id, topic_id, subscription_id, dead_letter_topic_id, | ||
max_delivery_attempts=5 | ||
): | ||
"""Create a subscription with dead letter policy.""" | ||
# [START pubsub_dead_letter_create_subscription] | ||
|
@@ -108,6 +109,9 @@ def create_subscription_with_dead_letter_topic( | |
# TODO(developer): This is an existing dead letter topic that the subscription | ||
# with dead letter policy will forward dead letter messages to. | ||
# dead_letter_topic_id = "your-dead-letter-topic-id" | ||
# TODO(developer): This is an the maximum number of delivery attempts allowed | ||
# before a message gets dead lettered. | ||
# max_delivery_attempts = "your-max-delivery-attempts" | ||
danavaziri-ga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
publisher = pubsub_v1.PublisherClient() | ||
subscriber = pubsub_v1.SubscriberClient() | ||
|
@@ -117,7 +121,8 @@ def create_subscription_with_dead_letter_topic( | |
dead_letter_topic_path = publisher.topic_path(project_id, dead_letter_topic_id) | ||
|
||
dead_letter_policy = DeadLetterPolicy( | ||
dead_letter_topic=dead_letter_topic_path, max_delivery_attempts=10 | ||
dead_letter_topic=dead_letter_topic_path, | ||
max_delivery_attempts=max_delivery_attempts | ||
) | ||
|
||
with subscriber: | ||
|
@@ -259,7 +264,8 @@ def update_push_subscription(project_id, topic_id, subscription_id, endpoint): | |
|
||
|
||
def update_subscription_with_dead_letter_policy( | ||
project_id, topic_id, subscription_id, dead_letter_topic_id | ||
project_id, topic_id, subscription_id, dead_letter_topic_id, | ||
max_delivery_attempts=5 | ||
): | ||
"""Update a subscription's dead letter policy.""" | ||
# [START pubsub_dead_letter_update_subscription] | ||
|
@@ -276,6 +282,9 @@ def update_subscription_with_dead_letter_policy( | |
# TODO(developer): This is an existing dead letter topic that the subscription | ||
# with dead letter policy will forward dead letter messages to. | ||
# dead_letter_topic_id = "your-dead-letter-topic-id" | ||
# TODO(developer): This is an the maximum number of delivery attempts allowed | ||
# before a message gets dead lettered. | ||
# max_delivery_attempts = "your-max-delivery-attempts" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
|
||
publisher = pubsub_v1.PublisherClient() | ||
subscriber = pubsub_v1.SubscriberClient() | ||
|
@@ -290,11 +299,12 @@ def update_subscription_with_dead_letter_policy( | |
print(f"Before the update: {subscription_before_update}.") | ||
|
||
# Indicates which fields in the provided subscription to update. | ||
update_mask = FieldMask(paths=["dead_letter_policy.max_delivery_attempts"]) | ||
update_mask = FieldMask(paths=["dead_letter_policy"]) | ||
|
||
# Construct a dead letter policy you expect to have after the update. | ||
dead_letter_policy = DeadLetterPolicy( | ||
dead_letter_topic=dead_letter_topic_path, max_delivery_attempts=20 | ||
dead_letter_topic=dead_letter_topic_path, | ||
max_delivery_attempts=max_delivery_attempts | ||
) | ||
|
||
# Construct the subscription with the dead letter policy you expect to have | ||
|
@@ -339,12 +349,7 @@ def remove_dead_letter_policy(project_id, topic_id, subscription_id): | |
print(f"Before removing the policy: {subscription_before_update}.") | ||
|
||
# Indicates which fields in the provided subscription to update. | ||
update_mask = FieldMask( | ||
paths=[ | ||
"dead_letter_policy.dead_letter_topic", | ||
"dead_letter_policy.max_delivery_attempts", | ||
] | ||
) | ||
update_mask = FieldMask(paths=["dead_letter_policy"]) | ||
|
||
# Construct the subscription (without any dead letter policy) that you | ||
# expect to have after the update. | ||
|
@@ -676,6 +681,12 @@ def callback(message): | |
create_with_dead_letter_policy_parser.add_argument("topic_id") | ||
create_with_dead_letter_policy_parser.add_argument("subscription_id") | ||
create_with_dead_letter_policy_parser.add_argument("dead_letter_topic_id") | ||
create_with_dead_letter_policy_parser.add_argument( | ||
"max_delivery_attempts", | ||
type=int, | ||
nargs="?", | ||
default=5 | ||
) | ||
|
||
create_push_parser = subparsers.add_parser( | ||
"create-push", help=create_push_subscription.__doc__ | ||
|
@@ -707,6 +718,12 @@ def callback(message): | |
update_dead_letter_policy_parser.add_argument("topic_id") | ||
update_dead_letter_policy_parser.add_argument("subscription_id") | ||
update_dead_letter_policy_parser.add_argument("dead_letter_topic_id") | ||
update_dead_letter_policy_parser.add_argument( | ||
"max_delivery_attempts", | ||
type=int, | ||
nargs="?", | ||
default=5 | ||
) | ||
|
||
remove_dead_letter_policy_parser = subparsers.add_parser( | ||
"remove-dead-letter-policy", help=remove_dead_letter_policy.__doc__ | ||
|
@@ -777,6 +794,7 @@ def callback(message): | |
args.topic_id, | ||
args.subscription_id, | ||
args.dead_letter_topic_id, | ||
args.max_delivery_attempts, | ||
) | ||
elif args.command == "create-push": | ||
create_push_subscription( | ||
|
@@ -798,6 +816,7 @@ def callback(message): | |
args.topic_id, | ||
args.subscription_id, | ||
args.dead_letter_topic_id, | ||
args.max_delivery_attempts, | ||
) | ||
elif args.command == "remove-dead-letter-policy": | ||
remove_dead_letter_policy(args.project_id, args.topic_id, args.subscription_id) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
"This is the maximum number of delivery attempts allowed for a message before it gets delivered to a dead letter topic."
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.
nit: I think you still forgot the cross out "an" in "This is an the"
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.
Thank you for pointing that out!