Solution skill
Azure Service Bus in Node.js: sender/receiver lifecycle with identity
Complete solution
Shows how to fix azure Service Bus in Node.js: sender/receiver lifecycle with identity. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
For continuous processing use receiver.subscribe({ processMessage, processError }). For one-shot, use receiveMessages(1, { maxWaitTimeInMs: 5000 }). - Settle explicitly.
Steps
- ```js
import { ServiceBusClient } from "@azure/service-bus"; import { DefaultAzureCredential } from "@azure/identity";
const client = new ServiceBusClient( "YOUR-NAMESPACE.servicebus.windows.net", new DefaultAzureCredential() ); const sender = client.createSender("[queue]"); await sender.sendMessages({ body: "hello" }); await sender.close(); await client.close();
2. - **Close what you open.** Every `createSender`/`createReceiver` opens an AMQP link. In a long-running service, create once and reuse; in a script, close everything or the process hangs on exit.
- **subscribe() is streaming.** For continuous processing use `receiver.subscribe({ processMessage, processError })`. For one-shot, use `receiveMessages(1, { maxWaitTimeInMs: 5000 })`.
- **Settle explicitly.** With `receiveMode: "peekLock"` (the default), you must `completeMessage`, `abandonMessage`, `deferMessage`, or `deadLetterMessage`. Unsettled messages come back after the lock expires and get reprocessed, which looks like duplicate delivery.
- **Data role.** "Azure Service Bus Data Owner" (or Sender/Receiver) at the namespace scope.
- **Error handler is required.** `subscribe` without `processError` swallows connection drops silently.
3. Verify: send, receive with a 5s window, complete, check the queue depth returns to zero.
## When to use
You are seeing this: ``js import { ServiceBusClient } from "@azure/service-bus"; import { DefaultAzureCredential } from "@azure/identity"; const client = new ServiceBusClient( "YOUR-NAMESPACE.servicebus.windows.net", new DefaultAzureCredential() ); const sender =... Use this skill when you run into "Azure Service Bus in Node.js: sender/receiver lifecycle with identity".
## When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
## Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
## Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Evidence
Proactive skill. v7 client pattern verified against current docs. Evidence: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-nodejs-how-to-use-queues-mgmt
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_pRAdIt55wQOTbRCFngmArg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Azure Service Bus in Node.js: sender/receiver lifecycle with identity <span>— Vectle</span></a>