In the course of this tutorial we will see how it is possible to use the Raspberry Pi as a AMQP (Advanced Message Queuing Protocol) client and connect it to Windows Azure Service Bus that supports the AMQP version 1.0.
Obviously, the choice of the client library is almost forced : Apache Qpid Proton. This library developed in C still provides the bindings for other languages including Java, Python, and PHP but in the course of the article we will use only the native version.
Generally, the Raspberry Pi is used with the Raspbian (based on Debian) distribution which is a Linux distribution. This means that we can install the Qpid Proton library as we do on a normal Ubuntu distribution on a PC or on a virtual machine on Windows Azure.
Connect to the Raspberry Pi
All of the following operations can be performed by directly accessing the Raspberry Pi through a monitor, keyboard, and mouse connected to it or remotely through the use of SSH connection.
The latter solution is certainly the most convenient, using a tool like Putty and specifying the IP address of our board, the port (typically 22) and the connection type (SSH).
Once you are logged in the board, the next step is to install the main dependencies including GCC, CMAKE (build system used by Qpid) and the UUID library for generating unique identifiers (a bit as our dear Guid).
sudo apt-get install gcc cmake uuid-dev
As Qpid uses SSL and the Service Bus has this prerequisite for the connection, we need to install OpenSSL in our system (which actually may already be installed).
sudo apt-get install openssl
The presence of the OpenSSL library does not include the presence of the header files and static libraries needed for development. It is therefore necessary to install the libssl-dev.
sudo apt-get install libssl-dev
Not being interested in any other language bindings, we can avoid installing the packages for Python, PHP and so on, going directly to download the library source code on the official web site. Also, do not install the dependencies that affect the automatic generation of documentation.
Download and build of Qpid Proton
From the official web site we can get one of the mirror from which to download the library in the "Downloads" section and then execute the download using WGET tool.
pi@raspberrypi ~ $ wget http://apache.fastbull.org/qpid/proton/0.6/qpid-proton-0.6.tar.gz
--2014-04-16 07:09:52-- http://apache.fastbull.org/qpid/proton/0.6/qpid-proton-0.6.tar.gz
Resolving apache.fastbull.org (apache.fastbull.org)... 22.214.171.124
Connecting to apache.fastbull.org (apache.fastbull.org)|126.96.36.199|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 629147 (614K) [application/x-gzip]
Saving to: `qpid-proton-0.6.tar.gz'
100%[======================================>] 629,147 1.00M/s in 0.6s
2014-04-16 07:09:53 (1.00 MB/s) - `qpid-proton-0.6.tar.gz' saved [629147/629147]
After download, extract the file content.
tar xvfz qpid-proton-0.6.tar.gz
Enter the new folder you just created (Qpid-proton-0.6) and create a "build" folder in which the CMAKE tool will generate the related Makefile to build the library.
cmake -DCMAKE_INSTALL_PREFIX=/usr ..
The executed command output will be the following
pi@raspberrypi ~/qpid-proton-0.6/build $ cmake -DCMAKE_INSTALL_PREFIX=/usr ..
-- The C compiler identification is GNU 4.6.3
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- PN_VERSION: 0.6
-- Found Java: /usr/bin/java
-- Java version: 188.8.131.52. javac is at: /usr/bin/javac
-- Locations of Bouncycastle 1.47 jars: BOUNCYCASTLE_BCPROV_JAR-NOTFOUND BOUNCYCASTLE_BCPKIX_JAR-NOTFOUND
-- Won't build proton-j-impl because one or more Bouncycastle jars were not found. PROTON_JAR_DEPEND_DIR was: /usr/share/java
-- Found OpenSSL: /usr/lib/arm-linux-gnueabihf/libssl.so;/usr/lib/arm-linux-gnueabihf/libcrypto.so (found version "1.0.1e")
-- Looking for clock_gettime
-- Looking for clock_gettime - not found.
-- Looking for clock_gettime in rt
-- Looking for clock_gettime in rt - found
-- Looking for uuid_generate
-- Looking for uuid_generate - not found.
-- Looking for uuid_generate in uuid
-- Looking for uuid_generate in uuid - found
-- Looking for strerror_r
-- Looking for strerror_r - found
-- Looking for atoll
-- Looking for atoll - found
-- Could NOT find SWIG (missing: SWIG_EXECUTABLE SWIG_DIR)
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Looking for include file inttypes.h
-- Looking for include file inttypes.h - found
-- Can't locate the valgrind command; no run-time error detection
-- Cannot find rspec, skipping rspec tests
-- Cannot find both Java and Maven: testing disabled for Proton-J and JNI Bindings
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/qpid-proton-0.6/build
There are some warning related to the impossibility to find the Java runtime, Swig and Doxygen. As already mentioned, we are not interested in binding with other languages and automatic generation of documentation for which we can not worry about these warnings.
The last step is to use the MAKE tool to process the Makefile generated by CMAKE and install the library in the system.
sudo make install
After compilation, the library is installed in the system at /usr folder (as set in the first CMAKE command executed before) and in particular :
/usr/share/proton : it contains usage example;
/usr/bin e /usr/lib : library related files;
/usr/include/proton : header files to develop an application that uses the library;
Send and receive example on Service Bus
In order to test the library we can use send and receive simple examples distributed with the library itself during installation.
Also in this case we can use the CMAKE tool to generate the Makefile required to build (note that you need to run as Super User).
sudo mkdir build
sudo cmake ..
sudo make all
At the end of the build we will have the two executables recv and send corresponding to two simple applications that allow you to receive and send messages to a queue via AMQP.
To do this, create a new namespace for the Service Bus on the Windows Azure management portal and also a queue for it. In my case, the namespace is qpidproton.servicebus.windows.net and queue is named “myqueue”. Through the portal we have to get two fundamental paremeters for the connection that are SharedSecretIssuer (typically "owner") and the SharedSecretValue.
The address to connect to the Service Bus has the following structure:
The Service Bus use an SSL connection so we have to use AMQPS instead of simple AMQP.
In order to send a message with “Hello” into the body, we have to use send application with the following command.
./send –a amqps://username:email@example.com/queue_name Hello
In order to receive a message from the same queue we can use the recv application with the following command.
The output will be as follow.
Subject: (no subject)
I want to send messages to topic, I have tried the same example but its not working. Anyone please help me and send the samples for send and receive messages from topic in Azure.
Hi, thanks for the tutorial. However, I'm not able to get my connection to work. When I use the ./send -a amqps://username:password:@namespace.windows... command, I get this error message: LINK ERROR (amqp:unauthorized-access) Attempted to perform an unauthorized operation.. TrackingId:. Any ideas?
You are welcome ! I'm happy that now it works for you ! ;-)
awesome ! that did it. thanks for the fast response
However my sources.list has the following content deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi
I used default repos for Raspbian. Did you execute the following command to update repos ? sudo apt-get update
Hello Paolo, Interesting blog post! I just have my new Raspberry and installed Raspbian on it. I executed your commands: sudo apt-get install gcc cmake uuid-dev sudo apt-get install openssl sudo apt-get install libssl-dev But at the last command, it seems there's a 404 in searching the libssl-dev packages, making the install fail. What do you have in the sources.list file (/etc/apt) on your raspbian? I tried several repos, but don't get it to work. Thx
View this page in another language: