kid-sid/claude-spellbook/azure-service-bus

Claude Code and agent skill by kid-sid/claude-spellbook

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when implementing reliable message processing with Azure Service Bus — choosing between queues and topics, configuring peek-lock settlement, handling dead-lettered messages, or enforcing ordered processing with sessions.

Install

npx vskill@latest install kid-sid/claude-spellbook/azure-service-bus

SKILL.md

Azure Service Bus

Production patterns for Azure Service Bus using the azure-servicebus Python SDK.

When to Activate

  • Writing code that imports azure-servicebus or @azure/service-bus
  • Choosing between Service Bus queues, topics, and subscriptions
  • Implementing reliable message processing with peek-lock and settlement
  • Handling dead-lettered messages or poison message scenarios
  • Ensuring ordered processing with Service Bus sessions
  • Filtering messages per subscriber using SQL or correlation filters
  • Scheduling messages for future delivery or implementing deferred processing
  • Comparing Azure Service Bus against Azure Storage Queues or Event Hubs

Authentication

python
from azure.identity import DefaultAzureCredential
from azure.servicebus import ServiceBusClient
credential = DefaultAzureCredential()
client = ServiceBusClient(
fully_qualified_namespace="myns.servicebus.windows.net",
credential=credential,
)
# BAD: connection string embeds shared access key
client = ServiceBusClient.from_connection_string(
"Endpoint=sb://myns.servicebus.windows.net/;SharedAccessKeyName=..."
)
# GOOD: keyless via RBAC role (Azure Service Bus Data Sender / Receiver)
client = ServiceBusClient(
fully_qualified_namespace=os.environ["SERVICEBUS_NAMESPACE"],
credential=DefaultAzureCredential(),
)

Always use DefaultAzureCredential and assign the minimum RBAC role:

RolePermission
Azure Service Bus Data SenderSend messages only
Azure Service Bus Data ReceiverReceive and settle messages only
Azure Service Bus Data OwnerFull control — use only for admin tooling

Queues vs Topics/Subscriptions

FactorQueueTopic + Subscriptions
ConsumersSingle consumer groupMultiple independent consumers
Fan-outNoYes — each subscription gets a copy
FilteringNoYes — SQL or correlation filter per subscription
OrderingSessions onlySessions only
Use caseTask queue, work distributionEvent fan-out, pub/sub
Queue: Producer → [Queue] → Consumer A
Topic: Producer → [Topic] → [Sub: orders-billing] → Billing Service
→ [Sub: orders-shipping] → Shipping Service
→ [Sub: orders-analytics] → Analytics Service

Sending Messages

Single Message
python
from azure.servicebus import ServiceBusMessage
import json
def send_message(namespace: str, queue_name: str, body: dict, **props) -> None:
credential = DefaultAzureCredential()
with ServiceBusClient(namespace, credential) as client:
with client.get_queue_sender(queue_name) as sender:
message = ServiceBusMessage(
json.dumps(body),
subject=props.get("subject"),
correlation_id=props.get("correlation_id"),
message_id=props.get("message_id"), # deduplication key
time_to_live=props.get("ttl"), # timedelta
application_properties=props.get("properties", {}),
)
sender.send_messages(message)
Batch Send
python
def send_batch(namespace: str, queue_name: str, messages: list[dict]) -> None:
with ServiceBusClient(namespace, DefaultAzureCredential()) as client:
with client.get_queue_sender(queue_name) as sender:
batch = sender.create_message_batch()
for body in messages:
try:
batch.add_message(ServiceBusMessage(json.dumps(body)))
except ValueError:
# Batch full — send current batch and start a new one
sender.send_messages(batch)
batch = sender.create_message_batch()
batch.add_message(ServiceBusMessage(json.dumps(body)))
if len(batch):
sender.send_messages(batch)
Scheduled Messages
python
from datetime import datetime, timedelta, timezone
def schedule_message(namespace: str, queue_name: str, body: dict, delay: timedelta) -> int:
enqueue_at = datetime.now(timezone.utc) + delay
with ServiceBusClient(namespace, DefaultAzureCredential()) as client:
with client.get_queue_sender(queue_name) as sender:
seq_numbers = sender.schedule_messages(
ServiceBusMessage(json.dumps(body)),
enqueue_at,
)
return seq_numbers[0] # use to cancel with cancel_scheduled_messages()
Sending to a Topic
python
def publish_event(namespace: str, topic_name: str, event_type: str, payload: dict) -> None:
with ServiceBusClient(namespace, DefaultAzureCredential()) as client:
with client.get_topic_sender(topic_name) as sender:
sender.send_messages(ServiceBusMessage(
json.dumps(payload),
subject=event_type,
application_properties={"event_type": event_type},
))

Receiving Messages

Peek-Lock (Recommended)

Locks the message for processing; must be explicitly settled. Ensures at-least-once delivery.

python
from azure.servicebus import ServiceBusReceiveMode
def process_queue(namespace: str, queue_name: str, handler, max_messages: int = 10) -> None:
with ServiceBusClient(namespace, DefaultAzureCredential()) as client:
with client.get_queue_receiver(
queue_name,
receive_mode=ServiceBusReceiveMode.PEEK_LOCK,
max_wait_time=5,
) as receiver:
for msg in receiver.receive_messages(max_message_count=max_messages):
try:
body = json.loads(str(msg))
handler(body)
receiver.complete_message(msg) # ack — removes from queue
except Exception as e:
if msg.delivery_count >= 3:
receiver.dead_letter_message( # send to DLQ
msg,
reason="MaxRetriesExceeded",
error_description=str(e),
)
else:
receiver.abandon_message(msg) # nack — requeues with backoff
Settlement Methods
MethodEffectWhen to use
complete_messageRemoves from queueProcessing succeeded
abandon_messageReturns to queue; increments delivery_countTransient failure, will retry
dead_letter_messageMoves to DLQ with reasonPoison message, max retries exceeded
defer_messageParks with sequence number for later retrievalOut-of-order messages needing dependencies
Continuous Consumer (Long-Running)
python
import threading
def start_consumer(namespace: str, queue_name: str, handler, stop_event: threading.Event) -> None:
with ServiceBusClient(namespace, DefaultAzureCredential()) as client:
with client.get_queue_receiver(queue_name, max_wait_time=5) as receiver:
while not stop_event.is_set():
messages = receiver.receive_messages(max_message_count=10, max_wait_time=5)
if not messages:
continue
for msg in messages:
try:
handler(json.loads(str(msg)))
receiver.complete_message(msg)
except Exception as e:
logger.exception("message_processing_failed", extra={"delivery_count": msg.delivery_count})
receiver.abandon_message(msg)

Dead-Letter Queue

python
def process_dlq(namespace: str, queue_name: str) -> list[dict]:
dlq_path = f"{queue_name}/$deadletterqueue"
dead_letters = []
with ServiceBusClient(namespace, DefaultAzureCredential()) as client:
with client.get_queue_receiver(
dlq_path,
receive_mode=ServiceBusReceiveMode.PEEK_LOCK,
) as receiver:
for msg in receiver.receive_messages(max_message_count=50):
dead_letters.append({
"body": json.loads(str(msg)),
"reason": msg.dead_letter_reason,
"description": msg.dead_letter_error_description,
"delivery_count": msg.delivery_count,
"enqueued_at": msg.enqueued_time_utc,
})
receiver.complete_message(msg) # drain DLQ after inspection
return dead_letters

Alert when DLQ message count (ActiveMessageCount on the DLQ entity) exceeds zero.

Sessions (Ordered Processing)

Sessions guarantee FIFO ordering for messages with the same session_id. The queue/topic subscription must have requires_session=True.

python
# Send with session ID (all messages for the same order stay ordered)
def send_with_session(namespace: str, queue_name: str, session_id: str, body: dict) -> None:
with ServiceBusClient(namespace, DefaultAzureCredential()) as client:
with client.get_queue_sender(queue_name) as sender:
sender.send_messages(ServiceBusMessage(
json.dumps(body),
session_id=session_id,
))
# Receive a specific session
def process_session(namespace: str, queue_name: str, session_id: str, handler) -> None:
with ServiceBusClient(namespace, DefaultAzureCredential()) as client:
with client.get_queue_receiver(
queue_name,
session_id=session_id,
) as receiver:
for msg in receiver.receive_messages(max_message_count=100):
handler(json.loads(str(msg)))
receiver.complete_message(msg)
# Accept the next available session (let Service Bus assign)
def process_next_session(namespace: str, queue_name: str, handler) -> None:
with ServiceBusClient(namespace, DefaultAzureCredential()) as client:
with client.get_queue_receiver(
queue_name,
session_id=NEXT_AVAILABLE_SESSION, # from azure.servicebus
) as receiver:
for msg in receiver.receive_messages(max_message_count=100, max_wait_time=10):
handler(json.loads(str(msg)))
receiver.complete_message(msg)

Subscription Filters

python
from azure.servicebus.management import ServiceBusAdministrationClient, SqlRuleFilter, CorrelationRuleFilter
admin = ServiceBusAdministrationClient(
fully_qualified_namespace="myns.servicebus.windows.net",
credential=DefaultAzureCredential(),
)
# SQL filter — route by message property
admin.create_rule(
topic_name="orders",
subscription_name="orders-eu",
rule_name="eu-only",
filter=SqlRuleFilter("Region = 'EU'"),
)
# Correlation filter — cheaper, matches on built-in or application properties
admin.create_rule(
topic_name="orders",
subscription_name="orders-priority",
rule_name="priority-orders",
filter=CorrelationRuleFilter(
subject="order.placed",
application_properties={"priority": "high"},
),
)
# Remove the default catch-all rule when adding selective filters
admin.delete_rule("orders", "orders-eu", "$Default")
Filter typePerformanceFlexibilityUse when
TrueRuleFilterFastNoneSubscription receives everything (default)
CorrelationRuleFilterFastestSubject, correlation ID, app propertiesProperty-based routing
SqlRuleFilterSlowerFull SQL expressionComplex conditions across multiple properties
FalseRuleFilterFastNoneDisable subscription without deleting it

Retry Configuration

python
from azure.servicebus import ServiceBusClient
from azure.core.pipeline.policies import RetryPolicy

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
186
Repository forks
15
7-day trend score
26

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/kid-sid/claude-spellbook/azure-service-bus/badge)](https://verified-skill.com/skills/kid-sid/claude-spellbook/azure-service-bus)

Something wrong with this skill or its page? Tell us.