Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Debug and troubleshoot Azure Container Apps and Function Apps using logs, KQL, and health checks.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
troubleshooting/messaging/azure-servicebus-py.md
1# Azure Service Bus SDK — Python23Package: `azure-servicebus` | [README](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/servicebus/azure-servicebus/) | [Full Troubleshooting Guide](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/servicebus/azure-servicebus/TROUBLESHOOTING.md)45## Common Errors67| Exception | Cause | Fix |8|-----------|-------|-----|9| `ServiceBusAuthenticationError` | Invalid credentials | Check connection string, regenerate SAS key |10| `ServiceBusAuthorizationError` | Missing Send/Listen claim | Assign `Azure Service Bus Data Owner/Sender/Receiver` RBAC role |11| `ServiceBusConnectionError` | Network or firewall | Check AMQP port 5671, try `TransportType.AmqpOverWebsocket` |12| `OperationTimeoutError` | Service didn't respond in time | Adjust retry config, verify network |13| `MessageLockLostError` | Processing exceeded lock duration | Use `AutoLockRenewer`, reduce processing time |14| `SessionLockLostError` | Session lock expired | Reconnect to session, keep renewing lock |15| `MessageSizeExceededError` | Message or batch too large | Reduce payload. Premium supports individual messages up to 100MB. Batch limit is computed from max message size on the client, so batches can also be impacted |1617## Enable Logging1819```python20import logging, sys2122handler = logging.StreamHandler(stream=sys.stdout)23handler.setFormatter(logging.Formatter("%(asctime)s | %(threadName)s | %(levelname)s | %(name)s | %(message)s"))24logger = logging.getLogger('azure.servicebus')25logger.setLevel(logging.DEBUG)26logger.addHandler(handler)2728# Enable AMQP frame tracing29from azure.servicebus import ServiceBusClient30client = ServiceBusClient(..., logging_enable=True)31```3233## AutoLockRenewer3435```python36from azure.servicebus import AutoLockRenewer3738renewer = AutoLockRenewer()39with receiver:40for message in receiver.receive_messages(max_message_count=10):41renewer.register(receiver, message, max_lock_renewal_duration=300)42# process message43receiver.complete_message(message)44```4546## Key Issues4748- **Mixing sync/async**: Don't use `time.sleep()` in async code; use `await asyncio.sleep()`.49- **Dead letter debugging**: Use `sub_queue=ServiceBusSubQueue.DEAD_LETTER` to inspect `dead_letter_reason` and `dead_letter_error_description`.50- **Always close clients**: Use `with` statement or call `close()` to avoid connection leaks.51