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-eventhubs-py.md
1# Azure Event Hubs SDK — Python23Package: `azure-eventhub` | [README](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventhub/azure-eventhub) | [Full Troubleshooting Guide](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventhub/azure-eventhub/TROUBLESHOOTING.md)45## Common Errors67| Exception | Cause | Fix |8|-----------|-------|-----|9| `EventHubError` | Base exception wrapping AMQP errors | Check `message`, `error`, `details` fields |10| `ConnectionLostError` | Idle connection disconnected | Auto-recovers on next operation; no action needed |11| `AuthenticationError` | Bad credentials or expired SAS | Regenerate key, check RBAC roles, verify connection string |12| `OperationTimeoutError` | Network or throttling | Check firewall, try WebSockets (port 443), increase timeout |1314## Retry Configuration1516> **Auth:** `DefaultAzureCredential` is for local development. See [auth-best-practices.md](auth-best-practices.md) for production patterns.1718```python19from azure.eventhub import EventHubProducerClient20from azure.identity import DefaultAzureCredential2122client = EventHubProducerClient(23fully_qualified_namespace="<your-namespace>.servicebus.windows.net",24eventhub_name="<your-eventhub>",25credential=DefaultAzureCredential(),26retry_total=3,27retry_backoff_factor=0.8,28retry_backoff_max=120,29retry_mode='exponential'30)31```3233## Consumer Client Retry Configuration3435> **Auth:** `DefaultAzureCredential` is for local development. See [auth-best-practices.md](auth-best-practices.md) for production patterns.3637Under heavy load, tune the retry policy on `EventHubConsumerClient` to reduce timeouts:3839| Parameter | Default | Description |40|-----------|---------|-------------|41| `retry_total` | 3 | Max retry attempts per operation |42| `retry_backoff_factor` | 0.8 | Backoff multiplier between retries (seconds) |43| `retry_backoff_max` | 120 | Max backoff interval (seconds) |44| `retry_mode` | `exponential` | `fixed` or `exponential` |4546```python47from azure.eventhub import EventHubConsumerClient48from azure.eventhub.extensions.checkpointstoreblob import BlobCheckpointStore49from azure.identity import DefaultAzureCredential5051credential = DefaultAzureCredential()52checkpoint_store = BlobCheckpointStore(53blob_account_url="https://<storage-account>.blob.core.windows.net",54container_name="<checkpoint-container>",55credential=credential56)5758client = EventHubConsumerClient(59fully_qualified_namespace="<your-namespace>.servicebus.windows.net",60eventhub_name="<your-eventhub>",61consumer_group="$Default",62credential=credential,63checkpoint_store=checkpoint_store,64retry_total=5,65retry_backoff_factor=1.0,66retry_backoff_max=120,67retry_mode='exponential'68)69```7071## Enable Logging7273```python74import logging, sys7576handler = logging.StreamHandler(stream=sys.stdout)77handler.setFormatter(logging.Formatter("%(asctime)s | %(threadName)s | %(levelname)s | %(name)s | %(message)s"))78logger = logging.getLogger('azure.eventhub')79logger.setLevel(logging.DEBUG)80logger.addHandler(handler)8182# Enable AMQP frame tracing83client = EventHubProducerClient(..., logging_enable=True)84```8586## Key Issues8788- **Buffered producer not sending**: Ensure enough `ThreadPoolExecutor` workers (one per partition). Use `buffer_concurrency` kwarg.89- **Blocking calls in async**: Run CPU-bound code in an executor; blocking the event loop impacts load balancing and checkpointing.90- **Consumer disconnected**: Expected during load balancing. If persistent with no scaling, file an issue.91- **Soft delete on checkpoint store**: Disable "soft delete" and "blob versioning" on the storage account used for checkpointing.92- **Always close clients**: Use `with` statement or call `close()` to avoid socket/connection leaks.9394## Checkpointing (BlobCheckpointStore)9596Package: `azure-eventhub-checkpointstoreblob` (sync) / `azure-eventhub-checkpointstoreblob-aio` (async)9798See the [Consumer Client Retry Configuration](#consumer-client-retry-configuration) section above for a full `EventHubConsumerClient` example with `BlobCheckpointStore`.99100**Common issues:**101- **Soft delete / blob versioning**: Disable both on the storage account — they cause large delays during load balancing.102- **HTTP 412/409 from storage**: Normal during partition ownership negotiation; not an error.103- **Checkpoint frequency**: Checkpoint after processing each batch, not each event, to avoid storage throttling.104