Apache Qpid (https://qpid.apache.org/index.html) is a messaging tool that supports AMQP amongst other things. I recently set this up locally (running on Mac OS High Sierra 10.13.3) and was overwhelmed with the documentation (it’s pretty good but no single tutorial to show the basics ) – hence this post.
I just wanted to set up a simple messaging (hello world type) infrastructure that would have the following components:
- A Messaging Server
This is the ‘thing’ that runs like a server and is responsible for receiving and routing messages among another mind-boggling number of things it can do. The component that does this (for Java folks) is downloadable at:
Click on the ‘Qpid Broker-J 7.0.1’ (latest at the time of writing), and download the tar file to a suitable location. Untar it and simply run:
<qpid server location>/bin/qpid-server
By default, the Broker starts up on HTTP port 8080 and AMQP port: 5672.
Why do these ports matter?
HTTP Port is used by the QPID Broker management console.
AMQP Port: This is required by the JMS client (the piece of code which will send a message) when creating a connection (more on this later).
However, with a little foresight, you might not want this when running locally (8080 is a commonly used port for local Tomcat and other app servers). So, you can restart the Broker by passing a different port number like so:
<qpid server location>/bin/qpid-server -prop “qpid.amqp_port=10000” -prop “qpid.http_port=10001”
You’ll know if the server started up fine if you see something similar in the console/terminal:
Now, I can access the Broker management console UI like so:
The default credential is: admin/admin
Once logged in, you should see a similar screen:
So far, so good. Now I need the other piece of the puzzle. A ‘client’ that can publish some message and consume the message.
2. Messaging client
Here’s what I followed for setting up the client:
However, I didn’t download the sample as it is. I was using IntelliJ, so I created a blank Maven project. My pom.xml looks like:
Also, I changed the jndi.properties to accommodate the new port that I previously assigned:
Ok, so I changed the queue name too (I mean, who wants a queue named queue, right?)
Now, I was being dumb and ran the program and was promptly greeted with the following exception:
Caused by: javax.jms.JMSSecurityRuntimeException: No supported mechanism, or none usable with the available credentials. Server offered: [CRAM-MD5, SCRAM-SHA-1, SCRAM-SHA-256]Caused by: javax.jms.JMSSecurityRuntimeException: No supported mechanism, or none usable with the available credentials. Server offered: [CRAM-MD5, SCRAM-SHA-1, SCRAM-SHA-256] at org.apache.qpid.jms.sasl.SaslMechanismFinder.findMatchingMechanism(SaslMechanismFinder.java:103)
The first step (like most things in life) was to ask Google if this meant anything. Nothing substantial came up. Some posts indicated that this might have to do with the SASL supported etc. A lot of BS that hardly helped.
So, I went back to the sample and actually READ through the instructions. I missed two critical steps:
a. You need to create the damn queue (remember the testqueue from jndi.properties?). Ok. How to create a queue? Google again. The first link that came up:
Nope. Not what I wanted.
Back to Qpid documentation. Found this:
Duh! Create a queue named ‘testqueue’. Just leave the remaining defaults. I need it up and running for the time being.
Another dummy tip: Double click on the ‘defaults’ node under ‘virtualhosts’ which will bring up the following screen:
Scroll down, and you should see a ‘Add queue’ button. Click it. click it NOW!
Enter the name and you are done.
The queue was created, and you should now see another node under ‘default’ node. (Yes, you can double-click on the queue name and it will show you the details now)
b. You need to pass the following as JVM parameters in order to get rid of the error, like so:
Why do we need this? Well, by default the server is using ‘passwordFile’ as the authentication mechanism. So, I need to pass some credentials that the server will recognize.
How does one know the list of credentials that can be identified by the server when using this kind of authentication?
The list can be found in the <qpid server untar’ed location>/7.0.1/etc/passwd file.
AHA! Now the exception makes so much sense !!
I got sidetracked a bit. My apologies.
But, finally, now when I ran the HelloWorld client, I got this in the console:
How did I know the client was able to send the message and receive it? Check the Broker console:
Note the ‘Delivered’ statistics.
Yup. Got this simple hello world to work and learnt a lot of terminologies in the process.
Github source: https://github.com/trishulpani/qpid-helloworld