Now that we’ve installed MQ, it’s time to try it out. If you haven’t read it, you can go to Installing IBM MQ on Linux to learn how to do it.
In this article, I’ll show you the basics of IBM MQ and what it can do for your applications’ infrastructure.
As the name points out, MQ relies on… you guessed it, message queues. Message queues are managed by… You guessed it again: queue managers.
So, the first thing to do before creating your own queues is to create a queue manager.
When IBM MQ is installed it creates an mqm user group and an mqm user. MQ administrators have to be in the mqm user group. The user mqm is also part of this group.
The most basic way to create a queue manager is with the ctrmqm command. To create the QM1 queue manager, we can use the command below:
ctrmqm QM1
There are other options, as for most MQ commands, but this is enough for now.
If there are no errors in the creation of the new queue manager, you should see the following output:
Directory ‘/var/mqm/qmgrs/QM1’ created.
The queue manager is associated with installation ‘Installation1’.
Creating or replacing default objects for queue manager ‘QM1’.
Default objects statistics : 84 created. 0 replaced. 0 failed.
Completing setup.
Setup completed.
After creating the queue manager, it must be running before it can be configured.
strmqm QM1
If every thing is OK, you should see the output:
IBM MQ queue manager ‘QM1’ starting.
The queue manager is associated with installation ‘Installation1’.
5 log records accessed on queue manager ‘QM1’ during the log replay
phase.
Log replay for queue manager ‘QM1’ complete.
Transaction manager state recovered for queue manager ‘QM1’.
IBM MQ queue manager ‘QM1’ started using V9.1.0.0.
After creating and starting our new queue manager, we have to create queues for it to be useful. Other basic MQ objects have to be created in order for our applications to be able to connect to MQ: at least one listener, which determines which IP address and TCP port MQ listens on, and one server connection channel (I’ll discuss MQ channels in another post).
For now, because our queue manager is “empty” there is only one way to add objects to it, and that is with the runmqsc command.
runmqsc QM1
First, define a listener
DEFINE LISTENER(LISTENER1.TCP) TRPTYPE(TCP) PORT(1414)
This tells MQ to listen on TCP port 1414 (this is the default, by the way). Because we didn’t specify an IP address, MQ will listen on all network interfaces.
Then, define a server connection channel (for applications to connect to MQ):
DEFINE CHANNEL(CLNT.APP) CHLTYPE(SVRCONN)
The SVRCONN channel type is used by applications to connect remotely to MQ.
Now, for just a quick explanation about MQ objects’ naming and commands.
IBM MQ converts everything to upper case, except what is enclosed in single quotes. So
define qlocal(queue1)
is equivalent to
DEFINE QLOCAL(QUEUE1)
Should you want to create a queue named queue1 (in lower case) you have to type
DEFINE QLOCAL(‘queue1’)
MQSC commands can by typed in lower or upper case and some can be abbreviated, such as DEFINE (DEF), DELETE (DEL) and ALTER (ALT). Some options can also be abbreviated, such as QL for QLOCAL. The above command can, thus, be typed as
DEF QL(‘queue1’)
Now that we’ve created our first queue, it’s about time we tested it. If you installed IBM MQ’s samples (you did install them, didn’t you?), we can use amqsput and amqsget samples to test our new queue.
Open a connection to the MQ server (SSH or any other remote access method) and issue the following:
/opt/mqm/samp/bin/amqsput queue1 QM1
Write something; every time you press Enter a new message is created in the queue.
Hi
Testing… 1… 2… 3…
Last message
To exit, press Control‑D.
Now, if you check the queue depth (with the DISPLAY QLOCAL(‘queue1’) CURDEPTH command), you’ll notice it is now 3:
runmqsc QM1
DISPLAY QLOCAL(‘queue1’) CURDEPTH
1 : DISPLAY QLOCAL(‘queue1’) CURDEPTH
AMQ8409I: Display Queue details.
QUEUE(queue1) TYPE(QLOCAL)
CURDEPTH(3)
Issue the amqsget:
/opt/mqm/samp/bin/amqsget queue1 QM1
Sample AMQSGET0 start
message <Hi>
message <Testing… 1… 2… 3…>
message <Last message>
If you check the queue again, you’ll notice its depth is now 0 (zero):
runmqsc QM1
DISPLAY QLOCAL(‘queue1’) CURDEPTH
1 : DISPLAY QLOCAL(‘queue1’) CURDEPTH
AMQ8409I: Display Queue details.
QUEUE(queue1) TYPE(QLOCAL)
CURDEPTH(0)
That’s all for now, folks! See you in the next installment of this article series.