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 primary goal here is get node up and running and have a reasonable IDE to work with. Web Matrix is a great tool
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
We have already installed Web Matrix. It is time to start writing hello world. Select from the template gallery.
From the File menu, choose Site from Template Gallery
Figure 3: Web Matrix Template Gallery
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
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 is where you will actually add the needed node packages.
Figure 6: The command line
You will need to fix your path to make sure the node executables are available.
Figure 7: Setting the Path
Note that we have some parameters available through NPM.
Figure 8: Using NPM
Simply type in npm install azure
Figure 9: Installing the Azure Package
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
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
Here is some code to read messages from the Azure Service Bus 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.