You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -127,6 +131,34 @@ The Service Bus APIs generate the following exceptions in `azure.servicebus.exce
127
131
128
132
-**AutoLockRenewTimeout:** The time allocated to renew the message or session lock has elapsed. You could re-register the object that wants be auto lock renewed or extend the timeout in advance.
129
133
134
+
#### Python-Specific Considerations
135
+
136
+
-**ImportError/ModuleNotFoundError:** Common when Azure Service Bus dependencies are not properly installed. Ensure you have installed the correct package version:
137
+
```bash
138
+
pip install azure-servicebus
139
+
```
140
+
141
+
-**TypeError:** Often occurs when passing incorrect data types to Service Bus methods:
142
+
```python
143
+
# Incorrect: passing string instead of ServiceBusMessage
144
+
sender.send_messages("Hello World") # This will fail
145
+
146
+
# Correct: create ServiceBusMessage objects
147
+
from azure.servicebus import ServiceBusMessage
148
+
message = ServiceBusMessage("Hello World")
149
+
sender.send_messages(message)
150
+
```
151
+
152
+
-**ConnectionError/socket.gaierror:** Network-level errors that may require checking DNS resolution and network connectivity:
asyncwith sb_manager.client.get_queue_sender(queue_name) as sender:
1180
+
message = ServiceBusMessage(message_content)
1181
+
await sender.send_messages(message)
1182
+
return {"status": "sent"}
1183
+
```
1184
+
910
1185
## Frequently asked questions
911
1186
912
1187
### Q: Why am I getting connection timeout errors?
@@ -938,17 +1213,99 @@ Check the `dead_letter_reason` and `dead_letter_error_description` properties on
938
1213
### Q: How do I process messages faster?
939
1214
940
1215
**A:** Consider:
941
-
- Using concurrent message processing
1216
+
- Using concurrent message processing (with separate client instances per thread/task)
942
1217
- Optimizing your message processing logic
943
-
- Using `prefetch_count` to pre-fetch messages
944
-
- Scaling out with multiple receivers
1218
+
- Using `prefetch_count` to pre-fetch messages (use with caution - see note below)
1219
+
- Scaling out with multiple receivers (on different clients)
1220
+
1221
+
**Note on prefetch_count:** Be careful when using `prefetch_count` as it can cause message lock expiration if processing takes too long. The client cannot extend locks for prefetched messages.
945
1222
946
1223
### Q: What's the difference between `complete_message()` and `abandon_message()`?
947
1224
948
1225
**A:**
949
1226
-`complete_message()`: Removes the message from the queue/subscription (successful processing)
950
1227
-`abandon_message()`: Returns the message to the queue/subscription for reprocessing
951
1228
1229
+
**Important:** Due to Python AMQP implementation limitations, these operations return immediately without waiting for service acknowledgment. Implement idempotent processing to handle potential redelivery.
1230
+
1231
+
### Q: How do I handle message ordering?
1232
+
1233
+
**A:**
1234
+
- Use **sessions** for guaranteed message ordering within a session
1235
+
- For partitioned entities, messages with the same partition key maintain order
1236
+
- Regular queues do not guarantee strict FIFO ordering
1237
+
1238
+
```python
1239
+
# Using sessions for ordered processing
1240
+
with client.get_queue_receiver(queue_name, session_id="order_123") as session_receiver:
### Q: How do I monitor message processing performance?
1283
+
1284
+
**A:**
1285
+
```python
1286
+
import time
1287
+
import logging
1288
+
from contextlib import contextmanager
1289
+
1290
+
@contextmanager
1291
+
defmessage_processing_timer(message_id):
1292
+
"""Context manager to time message processing"""
1293
+
start_time = time.time()
1294
+
try:
1295
+
yield
1296
+
finally:
1297
+
processing_time = time.time() - start_time
1298
+
logging.info(f"Message {message_id} processed in {processing_time:.3f}s")
1299
+
1300
+
# Usage
1301
+
defprocess_with_monitoring(receiver, message):
1302
+
with message_processing_timer(message.message_id):
1303
+
# Your processing logic
1304
+
result = process_message(message)
1305
+
receiver.complete_message(message)
1306
+
return result
1307
+
```
1308
+
952
1309
## Get additional help
953
1310
954
1311
Additional information on ways to reach out for support can be found in the [SUPPORT.md](https://github.com/Azure/azure-sdk-for-python/blob/main/SUPPORT.md) at the root of the repo.
0 commit comments