in Microsoft Azure, Protocols, Tutorials

AMQP to Azure Service Bus with Linux

In this post I’ll create message communication from a Linux CentOS VM with AMQP to Azure Service Bus. I choosed Linux because it is on a lot of IoT related devices. This post expands my previous blogpost about amqp visual studio and rabbitmq. That post was about AMQP on a local machine, this post is about a VM and Service Bus on Microsoft Azure. I’ll describe a few steps to make it work:

  1. Create the Service Bus on Microsoft Azure
  2. Create a Linux VM on Microsoft Azure
  3. Connect to the VM via SSH
  4. Install Apache Qpid Proton-C on the VM
  5. Create a Python script to send the message

1. Create the Service Bus on Microsoft Azure

When you create a Service Bus via the Azure portal it is not possible to use ACS. But for the AMQP communication you need ACS, so you can create a Service Bus with Powershell.

If you don’t have Azure Powershell download and install it first.

Open the Microsoft Azure Powershell window and run this command:

Get-AzurePublishSettingsFile

 

AMQP to Azure - Get PubSettings File

Get PubSettings File

It will bring you to a webpage where you can download your .pubsettings file. Login with your Azure credentials and choose the subscription where you want to create the Service Bus.

AMQP to Azure - Download PubSettings File

Download PubSettings File

Then run the command to import the .pubsettings file you just saved:

Import-AzurePublishSettingsFile "location path .pubsettings file"

 

AMQP to Azure - Import PubSettings File

Import PubSettings File

Now you are connected to the Azure subscription and ready to create the Service Bus with ACS:

New-AzureSBNamespace chris-amqp-ns -Location "West Europe" -CreateACSNamespace $true -NamespaceType Messaging

 

AMQP to Azure - Create Service Bus

Create Service Bus

Remember that ACS is needed for this scenario, so the parameter -CreateACSNamespace is $true. In the Azure Portal the new Service Bus is visible.

AMQP to Azure - Service Bus on Azure Portal

Service Bus on Azure Portal

Next you can create a queue to wich the messages will be send. In the Azure Portal, use the Custom Create, because you have to disable partitioning wich is enabled by default.

AMQP to Azure - Create Queue on Azure Portal

Create Queue on Azure Portal

AMQP to Azure - Disable Partitioning Queue

Disable Partitioning Queue

That’s it, the Service Bus is ready!

2. Create a Linux VM on Microsoft Azure

The next step is to create a VM on Azure. Go to the Azure portal and create a new VM from Gallary.

AMQP to Azure - Create VM on Azure Portal

Create VM on Azure Portal

Check the ‘Provide a password’ checkbox. You’ll need the username and password for the SSH connection in step 3.

AMQP to Azure - Create VM User on Azure Portal

Create VM User on Azure Portal

Keep the defaults in the next two steps and create the VM.

3. Connect to the VM via SSH

For the SSH connection I’ll use Putty. Other SSH client should also work. Find the DNS name and SSH portnumber of the created VM in the Azure portal. Fill these settings in Putty.

AMQP to Azure - Putty Configuration

Putty Configuration

Click Open to open the connection. Then fill the credentials you used when the VM was created.

AMQP to Azure - SSH Connection Login

SSH Connection Login

4. Install Apache Qpid Proton-C on the VM

The next step is to install Apache Qpid Proton-C. First you have to install a few packages. Run this command:

sudo yum install gcc cmake libuuid-devel

 

AMQP to Azure - Install Packages on VM

Install Packages on VM

Then run this command, for SSL support:

sudo yum install openssl-devel

Next run the command to install dependencies for binding:

sudo yum install swig python-devel ruby-devel php-devel java-1.6.0-openjdk

You’ll also need dependencies for python docs:

sudo yum install epydoc

Install wget so files can retrieved from the internet:

sudo yum install wget

Now you can download Qpid Proton:

sudo wget http://apache.proserve.nl/qpid/proton/0.8/qpid-proton-0.8.tar.gz

And extract the files:

sudo tar xvfz qpid-proton-0.8.tar.gz

You can find a directory named ‘qpid-proton-0.8’ when you use dir or ls. Change the directory to ‘qpid-proton-0.8’:

AMQP to Azure - Show Qpid Directory

Show Qpid Directory

Now create a new directory named ‘build’ and change the directory to that new folder:

mkdir build

 

cd build

Build and install the code using the following commands:

sudo cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DSYSINSTALL_BINDINGS=ON

 

sudo make all docs

 

sudo make install

5. Create a Python script to send the message

Finally, the last step! You are ready to create the script that will send a message to the Azure Service Bus. First change your directory to home/{username}/. Thats the directory with ‘qpid-proton-0.8’.

AMQP to Azure - HomeUsername Directory

HomeUsername Directory

Now create a new directory for the python script, and change the directory to that new folder:

sudo mkdir pythonscripts

 

cd pythonscripts

Create the script, I’ll use vi, but you can use the editor you want:

sudo vi sender.py

Paste this script in the created file:

import sys, optparse
from proton import *

messenger = Messenger()
message = Message()
message.address = "amqps://{ISSUER}:{KEY}@{servicebus namespace}.servicebus.windows.net/{queuename}"

message.body = u"This is a text string"
messenger.put(message)
print("***BEGIN SEND***")
messenger.send()
print("***END SEND***")

Fill the correct settings in the amqp address. For this blog it is “amqps://owner:{KEY}@chris-amqp-ns.servicebus.windows.net/chris-amqp-queue”
You can find the key in the Azure portal. There is a botton ‘connection information’ at the bottom of the Service Bus page. When you click that button you can find the key and the issuer.

AMQP to Azure - Access Service Bus

Access Service Bus

Now, run the sender. First check your queue:

AMQP to Azure - Queue Before Running Script

Queue Before Running Script

Run the script:

python ./sender.py

 

AMQP to Azure - Run The Script

Run The Script

And check the queue in the Azure portal. There should be one message more then before you ran the script.

AMQP to Azure - Queue After Running Script

Queue After Running Script

Conclusion

We created a Linux VM and a Service Bus on Microsoft Azure. We installed Apache Qpid Proton-C on the VM to send an AMQP message to the Service Bus.
Linux and AMQP are used a lot in IoT scenarios, but not everyone has devices to test AMQP messages. The scenario in this blog can be achieved with just an Azure subscription.
The next step is to install linux on a board like Galileo and send messages to the Azure Service Bus. Soon I’ll show how you can do that.

Write a Comment

Comment

Webmentions

  • cosmetic tooth implants Boynton Beach Forida

    … [Trackback]

    […] Read More on|Read More|Find More Informations here|Here you will find 4350 additional Informations|Informations to that Topic: chrisdenarend.com/amqp-to-azure-service-bus-with-linux/ […]

  • dental technicians in West Palm Beach Florida

    … [Trackback]

    […] Read More here|Read More|Read More Informations here|There you can find 51206 more Informations|Infos on that Topic: chrisdenarend.com/amqp-to-azure-service-bus-with-linux/ […]

  • dental in Jupiter FL

    … [Trackback]

    […] Read More on|Read More|Find More Informations here|Here you can find 29759 more Informations|Infos to that Topic: chrisdenarend.com/amqp-to-azure-service-bus-with-linux/ […]

  • DMPK

    … [Trackback]

    […] Read More on|Read More|Find More Infos here|There you can find 92143 more Infos|Informations on that Topic: chrisdenarend.com/amqp-to-azure-service-bus-with-linux/ […]

  • Bett

    … [Trackback]

    […] Read More on|Read More|Find More Informations here|Here you can find 3688 more Informations|Informations to that Topic: chrisdenarend.com/amqp-to-azure-service-bus-with-linux/ […]

  • dan anton military

    … [Trackback]

    […] Read More on|Read More|Read More Infos here|Here you can find 72181 additional Infos|Infos on that Topic: chrisdenarend.com/amqp-to-azure-service-bus-with-linux/ […]

  • danny anton

    … [Trackback]

    […] Read More on|Read More|Read More Infos here|There you will find 46942 additional Infos|Informations to that Topic: chrisdenarend.com/amqp-to-azure-service-bus-with-linux/ […]

  • check these guys out

    … [Trackback]

    […] Find More here|Find More|Find More Informations here|There you will find 80609 more Informations|Infos on that Topic: chrisdenarend.com/amqp-to-azure-service-bus-with-linux/ […]

  • 忠誠非泰傭, 印傭不忠誠, 菲僱愛回家, 騙案僱傭公司 忠誠賣老襯 Search到你好運

    … [Trackback]

    […] Find More on|Find More|Read More Infos here|There you will find 65932 more Infos|Informations on that Topic: chrisdenarend.com/amqp-to-azure-service-bus-with-linux/ […]

  • Elektrische Fußbodenheizungen

    … [Trackback]

    […] Find More on|Find More|Find More Infos here|Here you can find 40926 more Infos|Infos to that Topic: chrisdenarend.com/amqp-to-azure-service-bus-with-linux/ […]

  • pemandangan

    … [Trackback]

    […] Read More on|Read More|Find More Informations here|Here you will find 64336 additional Informations|Infos on that Topic: chrisdenarend.com/amqp-to-azure-service-bus-with-linux/ […]