Skip to content

Commit

Permalink
[Service Bus] fix deadletter sample + update README (#18261)
Browse files Browse the repository at this point in the history
(potential) fix for deadletter_messages_and_correct.py sample timeout exceeded error (over 300 minutes).
fixes: #18207
  • Loading branch information
swathipil authored Apr 23, 2021
1 parent 51c59ee commit 1750c25
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
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

0 comments on commit 1750c25

Please sign in to comment.