Stuart winchester in Redhat 5 minutes

Producing And Consuming Amq7 Messages With Stomp And Bash

A quick post showing a neat way to post and consume messages on Jboss AMQ7 using the STOMP protocol. The initial idea behind this was to do a simple bash health check that would produce a message to a queue, and then confirm that message by consuming it.

Ok, to get started clone this great github repo:

git clone https://github.com/flash-gordon/bash-mq.git
cd bash-mq

If you haven’t already, you’ll need socat installed on fedora:

sudo dnf install -y socat

If you have jboss amq up and running, you should now be able to connect and produce messages to it using the scripts in this repo. For example, I have an AMQ running at 192.168.122.18 with the STOMP acceptor open as per this $AMQ_INSTANCE/etc/broker.xml snippet. Running with username admin and password admin.

<!-- STOMP Acceptor. -->
<acceptor name="stomp">tcp://0.0.0.0:61613?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=STOMP;useEpoll=true</acceptor>

Send a message to the hello1 queue:

echo "hello world" | ./produce -h 192.168.122.18 -p 61613 -q hello1 -U admin -P admin

To confirm that this message was sent, consume it with:

./consume -h 192.168.122.18 -p 61613 -q hello1 -c ./echo-handler -U admin -P admin
Handling a message at Wed 17 Apr 14:44:30 BST 2019. Message follows:
hello world
(message ends)

Awesomesauce.

Creating a one-liner bash health-check

This is in order to produce/consume, and validate with grep in one line - using the exit code.

[user@localhost]$ echo "someCRAZYtextMsg" | ./produce -h 192.168.122.18 -p 61613 -q hello1 -U admin -P admin && ./consume -h 192.168.122.18 -p 61613 -q hello1 -c ./echo-handler -U admin -P admin 2>&1 | tail -10 | grep --line-buffered someCRAZYtextMsg
Binary file (standard input) matches
[user@localhost]$ echo $?
0
[user@localhost]$ echo "someFAILtextMsg" | ./produce -h 192.168.122.18 -p 61613 -q hello1 -U admin -P admin && ./consume -h 192.168.122.18 -p 61613 -q hello1 -c ./echo-handler -U admin -P admin 2>&1 | tail -10 | grep --line-buffered someCRAZYtextMsg
[user@localhost]$ echo $?
1

References