IBM MQ basics: the first queue

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 Lin­ux to learn how to do it.

In this arti­cle, I’ll show you the basics of IBM MQ and what it can do for your appli­ca­tions’ infrastructure.

As the name points out, MQ relies on… you guessed it, mes­sage queues. Mes­sage queues are man­aged by… You guessed it again: queue managers.

So, the first thing to do before cre­at­ing your own queues is to cre­ate a queue manager.

When IBM MQ is installed it cre­ates an mqm user group and an mqm user. MQ admin­is­tra­tors have to be in the mqm user group. The user mqm is also part of this group.

The most basic way to cre­ate a queue man­ag­er is with the ctr­mqm com­mand. To cre­ate the QM1 queue man­ag­er, we can use the com­mand below:

ctr­mqm QM1

There are oth­er options, as for most MQ com­mands, but this is enough for now.

If there are no errors in the cre­ation of the new queue man­ag­er, you should see the fol­low­ing output:

IBM MQ queue man­ag­er created.
Direc­to­ry ‘/var/mqm/qmgrs/QM1’ created.
The queue man­ag­er is asso­ci­at­ed with instal­la­tion ‘Installation1’.
Cre­at­ing or replac­ing default objects for queue man­ag­er ‘QM1’.
Default objects sta­tis­tics : 84 cre­at­ed. 0 replaced. 0 failed.
Com­plet­ing setup.
Set­up completed.

After cre­at­ing the queue man­ag­er, it must be run­ning before it can be configured.

str­mqm QM1

If every thing is OK, you should see the output:

IBM MQ queue man­ag­er ‘QM1’ starting.
The queue man­ag­er is asso­ci­at­ed with instal­la­tion ‘Installation1’.
5 log records accessed on queue man­ag­er ‘QM1’ dur­ing the log replay
phase.
Log replay for queue man­ag­er ‘QM1’ complete.
Trans­ac­tion man­ag­er state recov­ered for queue man­ag­er ‘QM1’.
IBM MQ queue man­ag­er ‘QM1’ start­ed using V9.1.0.0.

After cre­at­ing and start­ing our new queue man­ag­er, we have to cre­ate queues for it to be use­ful. Oth­er basic MQ objects have to be cre­at­ed in order for our appli­ca­tions to be able to con­nect to MQ: at least one lis­ten­er, which deter­mines which IP address and TCP port MQ lis­tens on, and one serv­er con­nec­tion chan­nel (I’ll dis­cuss MQ chan­nels in anoth­er post).

For now, because our queue man­ag­er is “emp­ty” there is only one way to add objects to it, and that is with the run­mqsc command.

run­mqsc QM1

First, define a listener

DEFINE LISTENER(LISTENER1.TCP) TRPTYPE(TCP) PORT(1414)

This tells MQ to lis­ten on TCP port 1414 (this is the default, by the way). Because we did­n’t spec­i­fy an IP address, MQ will lis­ten on all net­work interfaces.

Then, define a serv­er con­nec­tion chan­nel (for appli­ca­tions to con­nect to MQ):

DEFINE CHANNEL(CLNT.APP) CHLTYPE(SVRCONN)

The SVRCONN chan­nel type is used by appli­ca­tions to con­nect remote­ly to MQ.

Now, for just a quick expla­na­tion about MQ objects’ nam­ing and commands.

IBM MQ con­verts every­thing to upper case, except what is enclosed in sin­gle quotes. So

define qlocal(queue1)

is equiv­a­lent to

DEFINE QLOCAL(QUEUE1)

Should you want to cre­ate a queue named queue1 (in low­er case) you have to type

DEFINE QLOCAL(‘queue1’)

MQSC com­mands can by typed in low­er or upper case and some can be abbre­vi­at­ed, such as DEFINE (DEF), DELETE (DEL) and ALTER (ALT). Some options can also be abbre­vi­at­ed, such as QL for QLOCAL. The above com­mand can, thus, be typed as

DEF QL(‘queue1’)

Now that we’ve cre­at­ed our first queue, it’s about time we test­ed it. If you installed IBM MQ’s sam­ples (you did install them, did­n’t you?), we can use amqsput and amqs­get sam­ples to test our new queue.

Open a con­nec­tion to the MQ serv­er (SSH or any oth­er remote access method) and issue the following:

/opt/mqm/samp/bin/amqsput queue1 QM1

Write some­thing; every time you press Enter a new mes­sage is cre­at­ed in the queue.

Hi
Test­ing… 1… 2… 3…
Last message

To exit, press Control‑D.

Now, if you check the queue depth (with the DISPLAY QLOCAL(‘queue1’) CURDEPTH com­mand), you’ll notice it is now 3:

run­mqsc QM1
DISPLAY QLOCAL(‘queue1’) CURDEPTH
1 : DISPLAY QLOCAL(‘queue1’) CURDEPTH
AMQ8409I: Dis­play Queue details.
QUEUE(queue1)                          TYPE(QLOCAL)
CURDEPTH(3)

Issue the amqs­get:

/opt/mqm/samp/bin/amqsget queue1 QM1
Sam­ple AMQSGET0 start
mes­sage <Hi>
mes­sage <Test­ing… 1… 2… 3…>
mes­sage <Last message>

If you check the queue again, you’ll notice its depth is now 0 (zero):

run­mqsc QM1
DISPLAY QLOCAL(‘queue1’) CURDEPTH
1 : DISPLAY QLOCAL(‘queue1’) CURDEPTH
AMQ8409I: Dis­play Queue details.
QUEUE(queue1)                          TYPE(QLOCAL)
CURDEPTH(0)

That’s all for now, folks! See you in the next install­ment of this arti­cle series.

This entry was posted in Middleware, MQ and tagged , , , , , . Bookmark the permalink.

Leave a Reply