Skip to content
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

[Service Bus] fix deadletter sample + update README #18261

Merged
1 commit merged into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions sdk/servicebus/azure-servicebus/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ Both [sync version](https://github.com/Azure/azure-sdk-for-python/tree/master/sd
- List rule
- Get rule properties
- [failure_and_recovery.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/servicebus/azure-servicebus/samples/sync_samples/failure_and_recovery.py) - A demonstration of potential failure modes from an end-to-end send receive flow, as well as possible recovery patterns.
- [deadletter_messages_and_correct.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/servicebus/azure-servicebus/samples/sync_samples/deadletter_messages_and_correct.py) ([async_version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/servicebus/azure-servicebus/samples/async_samples/deadletter_messages_and_correct_async.py)) - Comprehensive example of moving messages to the dead-letter queue, retrieving messages from it, and resubmitting corrected messages back into main queue.
- [topic_subscription_with_rule_operations.py](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/servicebus/azure-servicebus/samples/sync_samples/topic_subscription_with_rule_operations.py) ([async_version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/servicebus/azure-servicebus/samples/async_samples/topic_subscription_with_rule_operations_async.py)) - Example to manage rules on topic subscriptions and to explore different forms of subscription filters.

## Prerequisites
- Python 2.7, 3.6 or later.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async def exceed_max_delivery(servicebus_client):
received_msgs = await receiver.receive_messages(max_wait_time=5)

async with dlq_receiver:
received_msgs = await dlq_receiver.receive_messages(max_message_count=10)
received_msgs = await dlq_receiver.receive_messages(max_message_count=10, max_wait_time=5)
for msg in received_msgs:
print("Deadletter message:")
print(msg)
Expand All @@ -59,7 +59,7 @@ async def exceed_max_delivery(servicebus_client):
async def receive_messages(servicebus_client):
receiver = servicebus_client.get_queue_receiver(queue_name=QUEUE_NAME)
async with receiver:
received_msgs = await receiver.receive_messages(max_message_count=10)
received_msgs = await receiver.receive_messages(max_message_count=10, max_wait_time=5)
for msg in received_msgs:
if msg.subject and msg.subject == "Good":
await receiver.complete_message(msg)
Expand All @@ -77,7 +77,7 @@ async def fix_deadletters(servicebus_client):
sub_queue=ServiceBusSubQueue.DEAD_LETTER)
msgs_to_send = []
async with dlq_receiver:
received_dlq_msgs = await dlq_receiver.receive_messages(max_message_count=10)
received_dlq_msgs = await dlq_receiver.receive_messages(max_message_count=10, max_wait_time=5)
for msg in received_dlq_msgs:
if msg.subject and msg.subject == "Bad":
msg_copy = ServiceBusMessage(str(msg), subject="Good")
Expand All @@ -88,7 +88,7 @@ async def fix_deadletters(servicebus_client):
print("Resending fixed messages")
await sender.send_messages(msgs_to_send)
async with receiver:
received_msgs = await receiver.receive_messages(max_message_count=10)
received_msgs = await receiver.receive_messages(max_message_count=10, max_wait_time=5)
for msg in received_msgs:
if msg.subject and msg.subject == "Good":
print("Received fixed message: Body={}, Subject={}".format(next(msg.body), msg.subject))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def exceed_max_delivery(servicebus_client):
received_msgs = receiver.receive_messages(max_wait_time=5)

with dlq_receiver:
received_msgs = dlq_receiver.receive_messages(max_message_count=10)
received_msgs = dlq_receiver.receive_messages(max_message_count=10, max_wait_time=5)
for msg in received_msgs:
print("Deadletter message:")
print(msg)
Expand All @@ -57,7 +57,7 @@ def exceed_max_delivery(servicebus_client):
def receive_messages(servicebus_client):
receiver = servicebus_client.get_queue_receiver(queue_name=QUEUE_NAME)
with receiver:
received_msgs = receiver.receive_messages(max_message_count=10)
received_msgs = receiver.receive_messages(max_message_count=10, max_wait_time=5)
for msg in received_msgs:
if msg.subject and msg.subject == "Good":
receiver.complete_message(msg)
Expand All @@ -75,7 +75,7 @@ def fix_deadletters(servicebus_client):
sub_queue=ServiceBusSubQueue.DEAD_LETTER)
msgs_to_send = []
with dlq_receiver:
received_dlq_msgs = dlq_receiver.receive_messages(max_message_count=10)
received_dlq_msgs = dlq_receiver.receive_messages(max_message_count=10, max_wait_time=5)
for msg in received_dlq_msgs:
if msg.subject and msg.subject == "Bad":
msg_copy = ServiceBusMessage(str(msg), subject="Good")
Expand All @@ -86,7 +86,7 @@ def fix_deadletters(servicebus_client):
print("Resending fixed messages")
sender.send_messages(msgs_to_send)
with receiver:
received_msgs = receiver.receive_messages(max_message_count=10)
received_msgs = receiver.receive_messages(max_message_count=10, max_wait_time=5)
for msg in received_msgs:
if msg.subject and msg.subject == "Good":
print("Received fixed message: Body={}, Subject={}".format(next(msg.body), msg.subject))
Expand Down