Sending Messages to Azure Service Bus Queue Using Node.js

Azure Service Bus is an excellent glue technology that we can use to handle the communication between our subsystems. We often use Azure Service Bus as the “queue” between our subsystems, which works great.

We usually build our backend systems using C#/.NET, but what if we need to send a message using Node.js?

Node.js is one of the more popular backend technologies. While it’s not necessarily our first pick in backend technologies at Don’t Panic Labs, many solutions are already using it, and not adding more technologies can benefit a project. Luckily, it is very easy to send messages from Node.js.

First, go to the Azure portal and create a service bus.

Creating a new service bus in Azure

Name your service bus.

Naming the new service bus

Go to your newly created service bus service and create a queue.

Creating a new queue

Name your queue.

Naming the new queue

Create a shared access policy.

Creating a shared policy

Since we will only be sending messages, let’s create a policy that only allows sending capabilities.

Creating a shared policy for only sending messages

To send a message, we will first need to install some Node.js packages.

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

Next, we need a JavaScript file (app.js) for sending these messages.

After sending a few messages, we should see them appear in the portal.

Sent message counts showing in the portal

Sending messages to a service bus queue is straightforward, even from Node.js. Are you using Node.js and Azure Service Bus? If so, shoot me a message on Twitter where I’m @chadmichel.

Related posts