In the first installment of the IBM MQ Basics, available here, I showed you basic queue creation and usage.
If IBM MQ would only allow local queues to be created and used, it would be less useful. One of the strengths of IBM MQ is the ability to link two or more queue managers and send messages to another queue manager.
In this article, I’m going to show you how to link two queue managers using a remote queues and channels.
First of all, you need two different queue managers. It doesn’t matter if they are in the same machine. I’m using two machines (actually, two virtual machines in my work machine, but the end result is absolutely the same).
I’m using the same queue manager that I configured in the last article of this series and another one, named QM2, with the same configuration, that is, a listener named LISTENER.TCP, with transport type (TRPTYPE) TCP, listenening on port 1414 and a channel for administration purposes of type server connection (SVRCONN) name CLNT.ADM.
Remote queues
A remote queue is a queue like any other, with a few notable exceptions:
- it is impossible to read from; it can only be written to;
- it refers to another queue (remote, local, or alias) in another queue manager;
- it does not occupy any hard disk space, except for the space needed to store its definition;
- you can (and should) specify a transmission queue (more on this type of queue later);
Channels and channel types
Communication between queue managers and between clients and queue managers is always done using channels.
Channels’ names can be at most 21 characters long.
We’ve already talked about one type of channel (the SVRCONN type). The server-connection channel is used for communicating between MQ client applications and a queue manager.
The other two types of channels I am going to talk about now are the sender channel (SDR) and receiver channel (RCVR) types.
As their name implies, the receiver channel is used as the receiving end of a sender channel. So, they always come in pairs.
The sender and receiver channels must have the same name. That’s how a sending queue manager identifies the receiving end.
Transmission queues
Finally, one must define a transmission queue before creating a sender channel.
This is a special type of local queue (you can write to and read from it, although it is not advisable) that serves as a temporary message store for messages being sent to a remote queue manager. If, for example, the remote queue manager is down for some reason or the network connection between the two queue managers is not available, the sending queue manager stores the messages destined to the remote one in this type of queue.
For each sender channel you need create a transmission queue.
Putting it all together
Configuring QM1
Ok. Let ‘s start.
In the following example, I’m going to create a remote queue in the QM1 queue manager that refers to a local queue in the QM2 queue manager.
Beginning with the QM1 queue manager.
First, create a transmission queue:
DEFINE QLOCAL(‘TO.QM2.X’) USAGE(XMITQ) TRIGGER TRIGDATA(TO.QM2) TRIGTYPE(FIRST)
This command defines something not discussed above: triggering. For now, let me just say that the last three options enables auto starting the channel named TO.QM2 when a message is placed in the TO.QM2.XmitQ transmission queue.
Next, we need to create a sender channel:
DEFINE CHANNEL(TO.QM2) CHLTYPE(SDR) CONNAME(‘mq2(1414)’) XMITQ(‘TO.QM2.X’)
This command defines a sender channel named TO.QM2 to host mq2, TCP port 1414 that uses the TO.QM2.XmitQ transmission queue.
Finally, to wrap the configurations in the QM1 queue manager, define the Q2.W remote queue:
DEFINE QREMOTE(Q2.W) RQMNAME(QM2) RNAME(Q2.R) XMITQ(‘TO.QM2.X’)
This remote queue definition has a configuration option which is not widely used: the option XMITQ. This option allows you to choose the sender channel which will be used by this remote queue by specifying its transmission queue. If you do not specify the transmission queue used by a remote one, the queue manager will choose an appropriate channel to send your messages through.
Configuring QM2
The configuration for the QM2 queue manager is very simple.
First, define a local queue with the name of the RNAME option of the remote queue you created in QM1 (Q2.R).
DEFINE QLOCAL(Q2.R)
Finally, define a receiver channel with the same name of the sender channel defined in the QM1 queue manager.
DEFINE CHANNEL(TO.QM2) CHLTYPE(RCVR)
Testing
In the mq1 machine run the following command
~$ /opt/mqm/samp/bin/amqsput Q2.W QM1
Sample AMQSPUT0 start
target queue is Q2.W
Hello, World!
end
End of messages
Sample AMQSPUT0 end
And, in the mq2 machine:
~$ /opt/mqm/samp/bin/amqsget Q2.R QM2
Sample AMQSGET0 start
message <Hello, World!>
message <end>
message <End of messages>
^C
That’s a wrap.
Stay tuned. In the next post, I’ll be talking about the publish/subscribe feature.
Pingback: MQGem Monthly (May 2019) | MQGem Software