New to Claude Skills? Learn how to install them →

sickn33 on GitHub

Azure Service Bus SDK

Free

Manage enterprise messaging with TypeScript seamlessly.

Get this skill

Free · Opens the source repo

What Azure Service Bus SDK does

The Azure Service Bus SDK for TypeScript provides a robust framework for implementing enterprise messaging solutions using queues, topics, and subscriptions. This skill is specifically designed for developers looking to integrate Azure's messaging capabilities into their TypeScript applications. With the SDK, you can easily send and receive messages, manage message sessions, and handle dead-letter queues, all while leveraging TypeScript's type safety features.

To get started, you need to install the necessary packages using npm, and set up your environment variables for the Azure Service Bus namespace, queue, topic, and subscription. Authentication is streamlined through the use of the DefaultAzureCredential, ensuring secure access to your messaging resources without hardcoding sensitive information.

The SDK supports various messaging patterns, including sending single or batch messages, receiving messages with different modes, and subscribing to messages for event-driven architectures. It also incorporates advanced features such as scheduled messages, message deferral, and peek operations, allowing you to build sophisticated messaging workflows. Additionally, best practices are highlighted to help you optimize your implementation, such as reusing client instances and handling errors effectively.

This skill is ideal for developers and architects working on cloud-based applications that require reliable messaging solutions. Whether you are building microservices, event-driven architectures, or integrating disparate systems, the Azure Service Bus SDK for TypeScript provides the necessary tools to ensure efficient and scalable communication between components.

When to use it

Use this skill when you need to implement messaging patterns in your TypeScript applications, such as sending and receiving messages, or managing subscriptions.

When not to use it

This skill may not be suitable for applications that do not require messaging capabilities or for those using other messaging services outside of Azure.

What you can build with it

Integrating Microservices

Use the Azure Service Bus SDK to facilitate communication between microservices in a cloud-based architecture.

Event-Driven Applications

Implement event-driven patterns by subscribing to topics and processing messages as they arrive.

Reliable Message Delivery

Ensure reliable message delivery by utilizing features like dead-letter queues and message sessions for ordered processing.

How to install Azure Service Bus SDK

View source

1. Install with the skills CLI

npx skills add sickn33/agentic-awesome-skills/azure-servicebus-ts --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by sickn33

Azure Service Bus SDK for TypeScript

Enterprise messaging with queues, topics, and subscriptions.

Installation

npm install @azure/service-bus @azure/identity

Environment Variables

SERVICEBUS_NAMESPACE=<namespace>.servicebus.windows.net
SERVICEBUS_QUEUE_NAME=my-queue
SERVICEBUS_TOPIC_NAME=my-topic
SERVICEBUS_SUBSCRIPTION_NAME=my-subscription

Authentication

import { ServiceBusClient } from "@azure/service-bus";
import { DefaultAzureCredential } from "@azure/identity";

const fullyQualifiedNamespace = process.env.SERVICEBUS_NAMESPACE!;
const client = new ServiceBusClient(fullyQualifiedNamespace, new DefaultAzureCredential());

Core Workflow

Send Messages to Queue

const sender = client.createSender("my-queue");

// Single message
await sender.sendMessages({
  body: { orderId: "12345", amount: 99.99 },
  contentType: "application/json",
});

// Batch messages
const batch = await sender.createMessageBatch();
batch.tryAddMessage({ body: "Message 1" });
batch.tryAddMessage({ body: "Message 2" });
await sender.sendMessages(batch);

await sender.close();

Receive Messages from Queue

const receiver = client.createReceiver("my-queue");

// Receive batch
const messages = await receiver.receiveMessages(10, { maxWaitTimeInMs: 5000 });
for (const message of messages) {
  console.log(`Received: ${message.body}`);
  await receiver.completeMessage(message);
}

await receiver.close();

Subscribe to Messages (Event-Driven)

const receiver = client.createReceiver("my-queue");

const subscription = receiver.subscribe({
  processMessage: async (message) => {
    console.log(`Processing: ${message.body}`);
    // Message auto-completed on success
  },
  processError: async (args) => {
    console.error(`Error: ${args.error}`);
  },
});

// Stop after some time
setTimeout(async () => {
  await subscription.close();
  await receiver.close();
}, 60000);

Topics and Subscriptions

// Send to topic
const topicSender = client.createSender("my-topic");
await topicSender.sendMessages({
  body: { event: "order.created", data: { orderId: "123" } },
  applicationProperties: { eventType: "order.created" },
});

// Receive from subscription
const subscriptionReceiver = client.createReceiver("my-topic", "my-subscription");
const messages = await subscriptionReceiver.receiveMessages(10);

Message Sessions

// Send session message
const sender = client.createSender("session-queue");
await sender.sendMessages({
  body: { step: 1, data: "First step" },
  sessionId: "workflow-123",
});

// Receive session messages
const sessionReceiver = await client.acceptSession("session-queue", "workflow-123");
const messages = await sessionReceiver.receiveMessages(10);

// Get/set session state
const state = await sessionReceiver.getSessionState();
await sessionReceiver.setSessionState(Buffer.from(JSON.stringify({ progress: 50 })));

await sessionReceiver.close();

Dead-Letter Handling

// Move to dead-letter
await receiver.deadLetterMessage(message, {
  deadLetterReason: "Validation failed",
  deadLetterErrorDescription: "Missing required field: orderId",
});

// Process dead-letter queue
const dlqReceiver = client.createReceiver("my-queue", { subQueueType: "deadLetter" });
const dlqMessages = await dlqReceiver.receiveMessages(10);
for (const msg of dlqMessages) {
  console.log(`DLQ Reason: ${msg.deadLetterReason}`);
  // Reprocess or log
  await dlqReceiver.completeMessage(msg);
}

Scheduled Messages

const sender = client.createSender("my-queue");

// Schedule for future delivery
const scheduledTime = new Date(Date.now() + 60000); // 1 minute from now
const sequenceNumber = await sender.scheduleMessages(
  { body: "Delayed message" },
  scheduledTime
);

// Cancel scheduled message
await sender.cancelScheduledMessages(sequenceNumber);

Message Deferral

// Defer message for later
await receiver.deferMessage(message);

// Receive deferred message by sequence number
const deferredMessage = await receiver.receiveDeferredMessages(message.sequenceNumber!);
await receiver.completeMessage(deferredMessage[0]);

Peek Messages (Non-Destructive)

const receiver = client.createReceiver("my-queue");

// Peek without removing
const peekedMessages = await receiver.peekMessages(10);
for (const msg of peekedMessages) {
  console.log(`Peeked: ${msg.body}`);
}

Key Types

import {
  ServiceBusClient,
  ServiceBusSender,
  ServiceBusReceiver,
  ServiceBusSessionReceiver,
  ServiceBusMessage,
  ServiceBusReceivedMessage,
  ProcessMessageCallback,
  ProcessErrorCallback,
} from "@azure/service-bus";

Receive Modes

// Peek-Lock (default) - message locked until completed/abandoned
const receiver = client.createReceiver("my-queue", { receiveMode: "peekLock" });
await receiver.completeMessage(message);   // Remove from queue
await receiver.abandonMessage(message);    // Return to queue
await receiver.deferMessage(message);      // Defer for later
await receiver.deadLetterMessage(message); // Move to DLQ

// Receive-and-Delete - message removed immediately
const receiver = client.createReceiver("my-queue", { receiveMode: "receiveAndDelete" });

Best Practices

  1. Use Entra ID auth - Avoid connection strings in production
  2. Reuse clients - Create ServiceBusClient once, share across senders/receivers
  3. Close resources - Always close senders/receivers when done
  4. Handle errors - Implement processError callback for subscription receivers
  5. Use sessions for ordering - When message order matters within a group
  6. Configure dead-letter - Always handle DLQ messages
  7. Batch sends - Use createMessageBatch() for multiple messages

Reference Documentation

For detailed patterns, see:

  • Queues vs Topics Patterns - Queue/topic patterns, sessions, receive modes, message settlement
  • Error Handling and Reliability - ServiceBusError codes, DLQ handling, lock renewal, graceful shutdown

When to Use

This skill is applicable to execute the workflow or actions described in the overview.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.

Frequently asked questions about Azure Service Bus SDK

Similar skills