This post is about reading Service Bus Queues messages from Node.js.
Creating the queues
Populating the queues
Downloading Web Matrix
Setting up node
Reading Service Bus Queues
Testing it locally
The last blog post
Code to create and populate queue
Code to Define message type
Code to Write to queue
This post is about getting node to read service bus queue messages
The primary goal here is get node up and running and have a reasonable IDE to work with. Web Matrix is a great tool
Install Web Matrix
Figure 1: Installing Web Matrix
Let’s get Node installed at the point. The download link for node is http://nodejs.org/
Figure 2: Installing Node.js on Windows
All the node files you will need are now find here c:\program files\nodejs
Starting web matrix and starting new project
We have already installed Web Matrix. It is time to start writing hello world. Select from the template gallery.
Select from Template Gallery
From the File menu, choose Site from Template Gallery
Figure 3: Web Matrix Template Gallery
Viewing the default project
You will need to provide a site name. An Azure Web Site will be provisioned for you. This will be where we deploy to once we are ready.
Figure 4: Defining An Azure Web Site
Getting your project’s folder
If you right mouse click in the solution you can choose ?Show file in Explorer.? This allows you to easily navigate to the folder if you copy the path to your clipboard. We will navigate to our project folder so we can install the azure node packages. We will run the utility ?npm? which allows you to install new packages from the npm website directly into our node project from Web Matrix.
Figure 5: Getting to the project folder
The command line
The command line is where you will actually add the needed node packages.
Figure 6: The command line
Adjusting the path
You will need to fix your path to make sure the node executables are available.
Figure 7: Setting the Path
A simple NPM command
Note that we have some parameters available through NPM.
Figure 8: Using NPM
Install the Azure Package
Simply type in npm install azure
Figure 9: Installing the Azure Package
Verifying the package(s)
You can see below we have a number of modules installed. You can expand the node_modules folder to see what is installed.
Figure 10: Viewing the Package
Writing some node.js code
Now we can start writing the code for node.js.
One of the first things you will need is the connection string for your Service Bus connection. You can get this at the portal.
You can also get it from the portal as seen below.
Figure 11: Getting the Service Bus Connection String
Some Node.js code (server.js)
Here is some code to read messages from the Azure Service Bus Queue.
Viewing the output from the messages in the queue
Now it is a simple case of running the code by hitting Run from the WebMatrix Toolbar. Here is what the output looks like:
Figure 13: Viewing Message from the Service Bus Queue
This is a simple post that illustrates how you can use Node.js to read messages from the Azure Service Bus.