Setting up Microsoft Azure Service Bus on the Raspberry Pi

The concept of the Internet of Things revolves around connecting everyday (household) objects to the internet. The important thing to consider is that all this data is being generated, but is only useful if something is being done with it. The Microsoft Azure Service bus allows you to process queues of such data and make it more useful.

In the previous post I showed you how I utilised a USB Webcam and a Raspberry Pi as a motion detection device. The next step in this process is to connect the Raspberry Pi to the Microsoft Azure Service Bus. Ordinarily you would use a Windows PC with Visual Studio and C#, but in this case we want to use Python since this is easily supported on the Rpi. We will utilise Qpid Proton which is a messaging library that has support for a Python API.

Once again, I’ll assume that you have a basic understanding of Linux terminal commands, and will be controlling the Rpi via PuTTY (SSH Client, see I have also previously set up a Service Bus queue, which I will use to send and receive sample messages.

The first step is to install Qpid Proton:


Then unpack it:

tar zxfv qpid-proton-0.7.tar.gz

Navigate to the directory, and display it’s contents:

cd qpid-proton-0.7/


Figure 1: Contents of the qpid-proton directory

The first thing to logically do is read the README file.



Figure 2: Contents of the README file

Figure 2 above shows the steps needed to build the API. Note that it says yum but we will use apt-get as that is the package manager for Ubuntu. Due to this, we will also have to look for the appropriate library names for the package manager. It is also worth noting that some of the packages are already installed by default so we shall not install them. We will also skip installation of files needed for Ruby and Java as we are only interested in using Python.

sudo apt-get install cmake
sudo apt-get install uuid-dev
sudo apt-get install openssl-dev
sudo apt-get install swig
sudo apt-get install python-dev

Once this is done, we will create the build directory for cmake and change the working directory to it.

mkdir build
cd build

Now run cmake, as specified in the README file.


As it builds, check that no errors are spotted, and that it finds the required files. The next step is to run:

sudo make install

This will take a couple of minutes to run as it compiles the necessary files.

After this step is completed, we are ready to test the new set up. There are a couple of example python scripts provided to allow you to send and receive messages. Let’s first go to the correct directory:

cd ..
cd examples/messenger/py


Figure 3: Contents of the Python examples directory

We will first attempt to send a file. Open the file by:

sudo nano

The only change I make is change the default address from amqp:// to the address of my previously set up Service Bus queue. Save and close the file.

Now we send a sample message “TestingforRpiblog1” using the script by:

python TestingforRpiblog1

I get a confirmation message: “sent: TestingforRpiblog1”. Success!

Now to receive the message. Open

sudo nano

Again, the only change I make is altering the address from the default amqp://  to the address of my working Service Bus queue. Save and close the file.

Now run



Figure 4: Sent and received the “TestingforRpiblog1” message

You should receive the message alongside some other information. Once the message is received, you will also run into an error-this is most likely since the receive file has reached the end of the queue and there are no more messages to receive. We won’t worry too much about this right now. Use ‘Cntrl+C’ to end the process.

If you run again, you should see that you receive the message again. This means that the message has not been taken out of the queue on the Service Bus. We need to make a few changes to ensure this is done correctly.

Open up the file again:

sudo nano

We will make 2 changes:

1. Add the following 2 lines after ‘mng.start ()’ :’’

mng.incoming_window = 1024
mng.outgoing_window = 1024

2. Change the commands under ‘try:’ to the following:

      print tkr

Save and close the file. Check that this works by receiving the message again. you should receive the same “TestingforRpiblog1” message, and have no errors. If you try again after a minute or so, it should not receive the same message again. Test a couple of times by sending and receiving messages, ensuring that no messages are received twice.


Figure 5: Sent and received test messages

Congratulations! That completed the set-up required to run the Service Bus from your Raspberry Pi. There are several other things you can do from here, such as send properties, carry out asynchronous sending and receiving, etc. Experiment and see how far you can get your devices on the Internet of Things!

Article by: Umang Rajdev

External Links/Further Reading: These are some of the links I referred to while carrying out this project.

One thought on “Setting up Microsoft Azure Service Bus on the Raspberry Pi

  1. Amir

    Hi Steve,

    I tried to follow your steps but struggling with the correct URL for the send test. As far as I could find out, ampq requires a username and password ( ampq://[username]:[password] ) and that you should use the default issuer as the user ( owner ) and the default key as password. There are different articles some telling me to url encode the default key (I tried with both) but I always receive an error:

    pi@(none) ~/qpid-proton-0.7/examples/messenger/py $ python TestingforRpiblog1
    [0x1b00890]:ERROR[-2] AMQP header mismatch: ‘AMQP\x02\x01\x00\x00’

    recv: Connection reset by peer
    [0x1b00890]:ERROR[-2] AMQP header mismatch: ” (connection aborted)

    CONNECTION ERROR connection aborted (remote)
    sent: TestingforRpiblog1

    I also tried to add /queuename to the url without any success. Could you give me some more details how you built the url or maybe u got an idea where the problem sits.




Leave a Reply

Your email address will not be published. Required fields are marked *