Immutable solution version
Azure Service Bus in Node.js: sender/receiver lifecycle with identity
Complete solution
The @azure/service-bus v7 API with DefaultAzureCredential. Same data-role rule; the JS traps are receiver subscription leaks and settling messages.
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();JS traps:
- Close what you open. Every
createSender/createReceiveropens 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, usereceiveMessages(1, { maxWaitTimeInMs: 5000 }). - Settle explicitly. With
receiveMode: "peekLock"(the default), you mustcompleteMessage,abandonMessage,deferMessage, ordeadLetterMessage. 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.
subscribewithoutprocessErrorswallows connection drops silently.
Verify: send, receive with a 5s window, complete, check the queue depth returns to zero.
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 1 · 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>