servicebus
azure_bootstrap.servicebus
¶
Tier 3 Service Bus helpers: consumer watchdog, DLQ growth alarm, daily digest.
Modules:
| Name | Description |
|---|---|
async_ext |
Service Bus extensions — async consumer, replay guard, multi-queue router. |
consumer |
Service-Bus-flavored re-exports of heartbeat primitives. |
consumer_wrapper |
End-to-end Service Bus message handler. |
dlq_alarm |
Dead-letter queue growth-rate alarm. |
dlq_digest |
Daily DLQ digest emails with embedded resubmit link + pending-alert summary. |
Classes:
| Name | Description |
|---|---|
MultiQueueRouter |
Route sends to named queues. |
ReplayGuard |
Bounded idempotency cache for message deduplication. |
InvalidResubmitToken |
Resubmit token is invalid (alias of |
Functions:
| Name | Description |
|---|---|
run_async_consumer |
Async receive loop with graceful shutdown on stop_event. |
service_bus_transport_type |
Return |
record_consumer_iteration |
Stamp the last-iteration time. Best-effort, never raises. |
record_message_settled |
Stamp the last-settled time. Best-effort, never raises. |
start_consumer_watchdog |
Spawn a daemon thread that alerts when consumer iteration stalls. |
handle_message |
Handle one received message end-to-end. |
check_dlq_growth_rate |
Peek the DLQ, compare to the previous sample, alert on excessive growth. |
reset_state |
Test-only. Refuses unless AZURE_BOOTSTRAP_ALLOW_RESET=1. |
build_dlq_digest_body |
5-column escaped HTML table: attachment, sender, dlq_time, reason, detail. |
run_dlq_digest |
Daily DLQ digest + pending-alerts summary email. |
ReplayGuard
¶
Bounded idempotency cache for message deduplication.
Source code in azure_bootstrap/servicebus/async_ext.py
InvalidResubmitToken
¶
Bases: InvalidActionToken
Resubmit token is invalid (alias of InvalidActionToken).
run_async_consumer
async
¶
run_async_consumer(client: Any, queue_name: str, handler: MessageHandler, *, stop_event: Event | None = None, max_wait: float = 5.0) -> None
Async receive loop with graceful shutdown on stop_event.
Source code in azure_bootstrap/servicebus/async_ext.py
service_bus_transport_type
¶
service_bus_transport_type() -> str
Return amqp or websocket from SERVICE_BUS_TRANSPORT_TYPE.
Source code in azure_bootstrap/servicebus/async_ext.py
record_consumer_iteration
¶
Stamp the last-iteration time. Best-effort, never raises.
Source code in azure_bootstrap/heartbeat/__init__.py
record_message_settled
¶
Stamp the last-settled time. Best-effort, never raises.
start_consumer_watchdog
¶
start_consumer_watchdog(stop_event: Event, *, interval_seconds: float | None = None, silence_threshold_seconds: float | None = None, resilence_window_seconds: float | None = None) -> Thread
Spawn a daemon thread that alerts when consumer iteration stalls.
The default resilence_window (1 hour) is intentionally longer than
the alerts dispatcher's 10-min dedup so sustained incidents page hourly,
not every 10 minutes.
Source code in azure_bootstrap/heartbeat/__init__.py
handle_message
¶
handle_message(receiver: SbReceiverProtocol, msg: Any, processor: MessageProcessor, *, schema: MessageSchema | None = None, correlation_field: str = 'correlation_id', extra_correlation_fields: tuple[str, ...] = (), source: str = 'consumer', lock_renewer: Any | None = None, counter_namespace: str = 'sb') -> tuple[bool, bool]
Handle one received message end-to-end.
Returns (processed: bool, failed: bool).
Source code in azure_bootstrap/servicebus/consumer_wrapper.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
check_dlq_growth_rate
¶
check_dlq_growth_rate(service_bus_repo: SbRepoProtocol, *, alert_threshold: int = 5, sample_window_minutes: int = 60) -> dict[str, int]
Peek the DLQ, compare to the previous sample, alert on excessive growth.
Returns {'current': N, 'delta': N, 'alerted': 0 or 1}.
Source code in azure_bootstrap/servicebus/dlq_alarm.py
reset_state
¶
Test-only. Refuses unless AZURE_BOOTSTRAP_ALLOW_RESET=1.
Source code in azure_bootstrap/servicebus/dlq_alarm.py
build_dlq_digest_body
¶
5-column escaped HTML table: attachment, sender, dlq_time, reason, detail.
Includes a "Resubmit all" button when resubmit_url is provided, else a
CLI hint.
Source code in azure_bootstrap/servicebus/dlq_digest.py
run_dlq_digest
¶
run_dlq_digest(service_bus_repo: Any, email_repo: EmailRepoProtocol, *, dev_recipients: Iterable[str], api_key: str, public_base_url: str, max_peek: int = 50, subject_prefix: str = '[DLQ digest]') -> dict[str, Any]
Daily DLQ digest + pending-alerts summary email.