Part 1 — Getting started on AMQP using IBM MQ

Before I begin

Step 1: Prepare the AMQP configuration

$ rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE}\t%{INSTPREFIXES}\n" | grep MQSeriesAMQPMQSeriesAMQP-9.1.0-4 /opt/mqm
$ cd /opt/mqm/amqp/samples
$ ./SampleMQM.sh
# This script creates an AMQP-enabled Queue manager to allow quick testing.# Get the name of the Queue Manager
QMGR=AMQP_SAMPLE_QM
# Get the Port number
PORT=${1-5672}
# Check the queue manager doesn't exist already
dspmq -m $QMGR >/dev/null 2>&1
rc=$?
if [ $rc -eq 0 ]; then
echo "Queue manager $QMGR already exists."
exit 1
fi
crtmqm $QMGR
strmqm $QMGR
# Allow user nobody to publish and subscribe on any topic.
# Note: Allowing the user nobody to do something in MQ, allows all users to do it!
setmqaut -m $QMGR -t qmgr -p nobody -all +connect
setmqaut -m $QMGR -t topic -n SYSTEM.BASE.TOPIC -p nobody -all +pub +sub
# Start the service
echo "START SERVICE(SYSTEM.AMQP.SERVICE)" | runmqsc $QMGR
# Create and start a channel
echo "DEFINE CHANNEL(SAMPLE.AMQP.CHANNEL) CHLTYPE(AMQP) PORT($PORT) MCAUSER('nobody')" | runmqsc $QMGR
sleep 2
echo "START CHANNEL(SAMPLE.AMQP.CHANNEL)" | runmqsc $QMGR

Step 2: Compile and run a sample Java code

$ git clone https://github.com/mqlight/java-mqlight.git
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<!-- version>3.0.0</version -->
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<excludePackageNames>com.ibm.mqlight.api.impl</excludePackageNames>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
-->
$ cd java-mqlight
$ mvn install -Dmaven.test.skip=true
[INFO] Reactor Summary for com.ibm.mqlight:mqlight-project 1.0-SNAPSHOT:
[INFO]
[INFO] com.ibm.mqlight:mqlight-project .................... SUCCESS [ 0.347 s]
[INFO] com.ibm.mqlight:mqlight-api ........................ SUCCESS [ 8.752 s]
[INFO] com.ibm.mqlight:mqlight-api-samples ................ SUCCESS [ 2.572 s]
[INFO] com.ibm.mqlight:mqlight-distribution ............... SUCCESS [ 0.487 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.726 s
[INFO] Finished at: 2020-04-18T17:47:51+10:00
[INFO] ------------------------------------------------------------------------
java -classpath ./lib/proton-j-0.12.1.jar:./lib/gson-2.2.4.jar:./lib/logback-classic-1.1.2.jar:./lib/logback-core-1.1.2.jar:./lib/netty-all-4.0.21.Final.jar:./lib/slf4j-api-1.7.5.jar:./lib/stateless4j-2.5.0.jar:./mqlight/target/mqlight-api-1.0-SNAPSHOT.jar:./mqlight-samples/target/mqlight-api-samples-1.0-SNAPSHOT.jar com.ibm.mqlight.api.samples.Receive -s amqp://ibmmqserver:5672
Connected to amqp://ibmmqserver:5672 using client-id AUTO_7e2839f
Subscribed to pattern: public
java -classpath ./lib/proton-j-0.12.1.jar:./lib/gson-2.2.4.jar:./lib/logback-classic-1.1.2.jar:./lib/logback-core-1.1.2.jar:./lib/netty-all-4.0.21.Final.jar:./lib/slf4j-api-1.7.5.jar:./lib/stateless4j-2.5.0.jar:./mqlight/target/mqlight-api-1.0-SNAPSHOT.jar:./mqlight-samples/target/mqlight-api-samples-1.0-SNAPSHOT.jar com.ibm.mqlight.api.samples.Send -s amqp://[ibmmqserver]:5672 -r 10
Connected to amqp://ibmmqserver:5672 using client-id AUTO_714422f
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Exiting
Subscribed to pattern: public
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!

Finally

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store