You are on page 1of 31

Title Of Document : MQ(MESSAGE QUEUE)

Author : G.S.GOUTHAM KUMAR


INDEX

1. INTRODUCTION
2. INTERCOMMUNICATION
3. CLUSTERING
4. TRIGGERING
5. SSL
6. CLIENT-SERVER COMMUNICATION
7. MULTI INSTANCE QUEUE MANAGER
8. BACKING UP AND RESTORING A QUEUE MANAGER
9. PUBLISH AND SUBSCRIBE
1.INTRODUCTION

Message Queue is a “Message Oriented Middleware” developed by IBM for business


messaging and queuing. It allows for sending and receiving messages across platforms with near real-
time efficiency and guaranteed delivery. Formerly called MQSeries, this middleware is widely used by
major industries around the globe because it simplifies testing and application development. This
eventually results to faster distribution of various business applications.
MQ runs on several platforms including Microsoft Windows, UNIX, and Linux among others.
With MQ, programs are able to easily interact with each other across different networks, since it also
uses a consistent API (application program interface).

MQ runs via message queuing wherein application programs communicate by writing and
receiving data to and from queues without necessarily having a link between them. This enables
programs to run on different machines but in different platforms. Applications can also be written in
different languages and can be transferred seamlessly from one platform to another.
2. INTERCOMMUNICATION

Intercommunication means sending messages from one queue manager to another. The
receiving queue manager can be on the same machine or another.

Intercommunication is of two types


 One-way Communication
 Two-way Communication

2.1 One-way Communication:


One-way communication takes place in one direction from sender to receiver. Message is put at
the server(sender) side and it is received at the client(receiver) side.

2.1.1 Sender side configuration:

 Create a Queue manger 'QM1' using command


crtmqm QM1
 Start the queue manager using command
strmqm QM1
 Run the Queue manager using the command
runmqsc QM1
 Inside the qmgr QM1
 Create a Listener using command
DEFINE LISTENER(LIST1) TRPTYPE(TCP) PORT(1414)
 Start the Listener using command
START LISTENER(LIST1)
 Check the Listener status to check if it started or not
DIS LSSTATUS(LIST1)
 Create a Transmission queue
DEFINE QLOCAL(QM2) USAGE(XMITQ)
 Create a Remote queue
DEFINE QREMOTE(QM1.RQ) RQMNAME(QM2) RNAME(QM2.LQ)
XMITQ(QM2)
 Create a Sender Channel
DEFINE CHANNEL(QM1.TO.QM2) CHLTYPE(SDR) TRPTYPE(TCP)
CONNAME('LOCALHOST(1415)') XMITQ(QM2)
 END

2.1.2 Receiver side Configuration:

 Create a Queue manger 'QM2' using command


crtmqm QM2
 Start the queue manager using command
strmqm QM2
 Run the Queue manager using the command
runmqsc QM2
 Inside the qmgr QM2
 Create a Listener using command
DEFINE LISTENER(LIST1) TRPTYPE(TCP) PORT(1415)
 Start the Listener using command
START LISTENER(LIST1)
 Check the Listener status to check if it started or not
DIS LSSTATUS(LIST1)
 Create a local queue
DEFINE QLOCAL(QM2.LQ)
 Create a Receiver Channel
DEFINE CHANNEL(QM1.TO.QM2) CHLTYPE(RCVR) TRPTYPE(TCP)
 END

2.1.3 Testing One-way Communication:

To start the communication


 Check the Queue manger status using command
dspmq
 Run QM1
runmqsc QM1
 Inside QM1
 Start Sender Channel
START CHANNEL(QM1.TO.QM2)
 Check the channel status if it is Running or not
DIS CHS(QM1.TO.QM2)
 END
 Go to the path “/opt/mqm/samp/bin”
 Put the Message at Sender using command
./amqsput QM1.RQ QM1
 Get the Message at Receiver using command
./amqsget QM2.LQ QM2

2.2 Two-way Communication:


Two-way communication takes place bi directional between sender to receiver. Message is put
from Sender to Receiver and Receiver to Sender.

2.2.1 Sender side configuration:

 Create a Queue manger 'QM1' using command


crtmqm QM1
 Start the queue manager using command
strmqm QM1
 Run the Queue manager using the command
runmqsc QM1
 Inside the qmgr QM1
 Create a Listener using command
DEFINE LISTENER(LIST1) TRPTYPE(TCP) PORT(1414)
 Start the Listener using command
START LISTENER(LIST1)
 Check the Listener status to check if it started or not
DIS LSSTATUS(LIST1)
 Create a Local Queue
DEFINE QLOCAL(QM1.LQ)
 Create a Transmission queue
DEFINE QLOCAL(QM2) USAGE(XMITQ)
 Create a Remote queue
DEFINE QREMOTE(QM1.RQ) RQMNAME(QM2) RNAME(QM2.LQ)
XMITQ(QM2)
 Create a Sender Channel
DEFINE CHANNEL(QM1.TO.QM2) CHLTYPE(SDR) TRPTYPE(TCP)
CONNAME('LOCALHOST(1415)') XMITQ(QM2)
 Create a Receiver Channel
DEFINE CHANNEL(QM2.TO.QM1) CHLTYPE(RCVR) TRPTYPE(TCP)
 END

2.2.2 Receiver side Configuration:


 Create a Queue manger 'QM2' using command
crtmqm QM2
 Start the queue manager using command
strmqm QM2
 Run the Queue manager using the command
runmqsc QM2
 Inside the qmgr QM2
 Create a Listener using command
DEFINE LISTENER(LIST1) TRPTYPE(TCP) PORT(1415)
 Start the Listener using command
START LISTENER(LIST1)
 Check the Listener status to check if it started or not
DIS LSSTATUS(LIST1)
 Create a Local queue
DEFINE QLOCAL(QM2.LQ)
 Create a Transmission queue
DEFINE QLOCAL(QM1) USAGE(XMITQ)
 Create a Remote queue
DEFINE QREMOTE(QM2.RQ) RQMNAME(QM1) RNAME(QM1.LQ)
XMITQ(QM1)
 Create a Receiver Channel
DEFINE CHANNEL(QM1.TO.QM2) CHLTYPE(RCVR) TRPTYPE(TCP)
 Create a Sender Channel
DEFINE CHANNEL(QM2.TO.QM1) CHLTYPE(SDR) TRPTYPE(TCP)
CONNAME('LOCALHOST(1414)') XMITQ(QM1)
 END

2.2.3 Two-way Communication:

To start the communication


 Check the Queue manger status using command
dspmq
 Run QM1
runmqsc QM1
 Inside QM1
 Start Sender Channel
START CHANNEL(QM1.TO.QM2)
 Check the channel status if it is Running or not
DIS CHS(QM1.TO.QM2)
 END
 Run QM2
runmqsc QM2
 Inside QM2
 Start Sender Channel
START CHANNEL(QM2.TO.QM2)
 Check the channel status if it is Running or not
DIS CHS(QM2.TO.QM1)
 END
 Go to the path “/opt/mqm/samp/bin”
 Put the Message at Sender using command
./amqsput QM1.RQ QM1
 Get the Message at Receiver using command
./amqsget QM2.LQ QM2
 Put the Message at Receiver using command
./amqsput QM2.RQ QM2
 Get the Message at Sender using command
./amqsget QM1.LQ QM1

3. CLUSTERING

Clustering is a way to logically group the Queue Managers. A cluster is a group of queue
managers set up in such a way that the queue managers can communicate directly with one another
over a single network, without the need for complex transmission queue, channel, and queue
definitions. The main advantage of clustering is work load balancing. If one system in the cluster fails
the other system having the full repositories can take control.

Cluster Configuration:
Here we create two queue managers A,B which hold full repositories and queue manager C
which hold partial repositories.

QMGR A
 Create a Queue manger ‘A’ using command
crtmqm A
 Start the queue manager using command
strmqm A
 Run the Queue manager using the command
runmqsc A
 Inside the A
 Create a Listener using command
DEFINE LISTENER(LIST1) TRPTYPE(TCP) PORT(1414)
 Start the Listener using command
START LISTENER(LIST1)
 Check the Listener status to check if it started or not
DIS LSSTATUS(LIST1)
 Create a Local Queue
DEFINE QLOCAL(INVNETQ) CLUSTER(INVENTORY)
 Alter queue manager repositories using command
ALTER QMGR REPOS(INVENTORY)
 Create a Cluster-Receiver Channel
DEFINE CHANNEL(TO.A) CHLTYPE(CLUSRCVR) TRPTYPE(TCP)
CONNAME('LOCALHOST(1416)') CLUSTER(INVENTORY)
 Create a Cluster-Sender Channel
DEFINE CHANNEL(TO.C) CHLTYPE(CLUSSDR) TRPTYPE(TCP)
CONNAME('LOCALHOST(1414)') CLUSTER(INVENTORY)
 Start Sender Channel
START CHL(TO.C)
 END

QMGR B
 Create a Queue manger ‘B’ using command
crtmqm B
 Start the queue manager using command
strmqm B
 Run the Queue manager using the command
runmqsc B
 Inside the B
 Create a Listener using command
DEFINE LISTENER(LIST1) TRPTYPE(TCP) PORT(1415)
 Start the Listener using command
START LISTENER(LIST1)
 Check the Listener status to check if it started or not
DIS LSSTATUS(LIST1)
 Create a Local Queue
DEFINE QLOCAL(INVNETQ) CLUSTER(INVENTORY)
 Alter queue manager repositories using command
ALTER QMGR REPOS(INVENTORY)
 Create a Cluster-Receiver Channel
DEFINE CHANNEL(TO.B) CHLTYPE(CLUSRCVR) TRPTYPE(TCP)
CONNAME('LOCALHOST(1416)') CLUSTER(INVENTORY)
 Create a Cluster-Sender Channel
DEFINE CHANNEL(TO.C) CHLTYPE(CLUSSDR) TRPTYPE(TCP)
CONNAME('LOCALHOST(1415)') CLUSTER(INVENTORY)
 Start the Sender Channel
START CHL(TO.C)
 END

QMGR C
 Create a Queue manger ‘C’ using command
crtmqm C
 Start the queue manager using command
strmqm C
 Run the Queue manager using the command
runmqsc C
 Inside the C
 Create a Listener using command
DEFINE LISTENER(LIST1) TRPTYPE(TCP) PORT(1416)
 Start the Listener using command
START LISTENER(LIST1)
 Check the Listener status to check if it started or not
DIS LSSTATUS(LIST1)
 Alter queue manager repositories using command
ALTER QMGR REPOS(INVENTORY)
 Create a Cluster-Receiver Channel
DEFINE CHANNEL(TO.C) CHLTYPE(CLUSRCVR) TRPTYPE(TCP)
CONNAME('LOCALHOST(1416)') CLUSTER(INVENTORY)
 Create a Cluster-Sender Channel
DEFINE CHANNEL(TO.A) CHLTYPE(CLUSSDR) TRPTYPE(TCP)
CONNAME('LOCALHOST(1414)') CLUSTER(INVENTORY)
 Start the Sender channel
START CHL(TO.A)
 END

Working:
When we put a message on cluster queue ‘INVENTQ’ using qmgr ‘C’ the message will be
received at ‘A’ . If qmgr ‘A’ is not available it’ll be routed to qmgr ‘B’. For suppose there is a lot of
load on ‘A’ some messages will be routed to ‘B’.
4. TRIGGERING

This feature enables an Application or Channel to start automatically when ever there are
messages ready for retrieval in a queue
Triggering is of two types
 Application Triggering
 Channel Triggering
4.1 Application Triggering:
 Create a Queue manger ‘A’ using command
crtmqm A
 Start the queue manager using command
strmqm A
 Run the Queue manager using the command
runmqsc A
 Inside the 'A'
 Create a Listener using command
DEFINE LISTENER(LIST1) TRPTYPE(TCP) PORT(1414)
 Start the Listener using command
START LISTENER(LIST1)
 Check the Listener status to check if it started or not
DIS LSSTATUS(LIST1)
 Create a Local Queue
DEFINE QLOCAL(INPUTQ)
 Alter Local Queue
ALTER QLOCAL(INPUTQ) TRIGGER TRIGTYPE(EVERY)
INITQ(SYSTEM.DEFAULT.INITIATION.QUEUE) PROCESS(PROC)
 Create a file ‘app.txt’ in ‘/tmp’ folder
cd /tmp
vi app.txt
(add the following line to app.txt)
/opt/mqm/samp/bin/amqsget INPUTQ A >> /tmp/out.txt
 Run qmgr A
runmqsc A
 Inside ‘A’
 Create a Process
DEFINE PROCESS(PROC) APPLTYPE(UNIX) APPLICID(‘/tmp/app.txt’)
 END
 Switch user as ‘mqm’
 Run the following command
runmqtrm –m A –q SYSTEM.DEFAULT.INITIATION.QUEUE
 Open new terminal
 Put the message
./amqsput INPUTQ A
 To see the message open ‘out.txt’ file

4.2 Channel Triggering:


QMGR A
 Create a Queue manger ‘A’ using command
crtmqm A
 Start the queue manager using command
strmqm A
 Run the Queue manager using the command
runmqsc A
 Define a Transmission Queue
DEFINE QL(B) USAGE(XMITQ)
 Define a Remote Queue
DEFINE QR(A.RQ) RQMNAME(B) RNAME(B.LQ) XMITQ(B)
 Define Sender channel
DEFINE CHL(A.TO.B) CHLTYPE(SDR) TRPTYPE(TCP)
CONNAME('LOCALHOST(1415)') XMITQ(B)
 Alter Transmission Queue
ALTER QL(B) TRIGGER TRIGTYPE(EVERY)
INITQ(SYSTEM.CHANNEL.INITQ) USAGE(XMITQ)

QMGR B
 Create a Queue manger ‘B’ using command
crtmqm B
 Start the queue manager using command
strmqm B
 Run the Queue manager using the command
runmqsc B
 Inside 'B'
 Define a Transmission Queue
DEFINE QL(B.LQ)
 Define Receiver channel
DEFINE CHL(A.TO.B) CHLTYPE(TCP) TRPTYPE(TCP)

Testing:
 Run the following command
runmqchi -m A -q SYSTEM.CHANELL.INITQ
 Now check the channel status they will be in running state

5. SSL
Secure Sockets Layer (SSL) is a protocol designed to allow the transmission of secure data over
an insecure network. SSL makes use of digital certificates to enable authentication between client and
server.

5.1 Two-way SSL Configuration :


 Create a qmgr 'A' and 'B'
 Configure two-way communication between 'A' and 'B'
 Check the communication link by putting and getting messages at both Client and Server
 Now Configure SSL for Queue Manager 'A'
 Run 'gsk7ikm' command
gsk7ikm
 It opens a GUI
 Create a new Key Database File
Key Database type : 'CMS'
File Name : 'a.*kdb'
Location :'/var/mqm/qmgrs/A/ssl/a'
 Next enter the password and select stash password to a file option
 Next create new self signed Certificate
Key Label : 'ibmwebspheremqa'
 Extract signer certificate
Certificate Name : 'a.arm'
Location : '/tmp/'
 close the GUI
 Run qmgr 'A'
 Inside qmgr 'A'
 Alter QMGR attributes
ALTER QMGR SSLKEY('/var/mqm/qmgrs/A/ssl/a') SSLEV(ENABLED)
 Alter the Sender channel
ALTER CHL(A.TO.B) CHLTYPE(SDR) SSLCIPH(RC4_MD5_US)
 Alter the Receiver channel
ALTER CHL(B.TO.A) CHLTYPE(RCVR) SSLCIPH(RC4_MD5_US)
 Refresh Security
REFRESH SECURITY TYPE(SSL)
 END
 Now Configure SSL for Queue Manager 'B'
 Run 'gsk7ikm' command
gsk7ikm
 It opens a GUI
 Create a new Key Database File
Key Database type : 'CMS'
File Name : 'b.kdb'
Location :'/var/mqm/qmgrs/B/ssl/b'
 Next enter the password and select stash password to a file option
 Next create new self signed Certificate
Key Label : 'ibmwebspheremqb'
 Extract signer certificate
Certificate Name : 'b.arm'
Location : '/tmp/'
 close the GUI
 Run qmgr 'B'
 Inside qmgr 'B'
 Alter QMGR attributes
ALTER QMGR SSLKEY('/var/mqm/qmgrs/B/ssl/b') SSLEV(ENABLED)
 Alter the Sender channel
ALTER CHL(B.TO.A) CHLTYPE(SDR) SSLCIPH(RC4_MD5_US)
 Alter the Receiver channel
ALTER CHL(A.TO.B) CHLTYPE(RCVR) SSLCIPH(RC4_MD5_US)
 Refresh Security
REFRESH SECURITY TYPE(SSL)
 END
 Now exchange signers between qmgrs 'A' and 'B'
 Run 'gsk7ikm' command
gsk7ikm
 Open Key Database File 'a.kdb'
Key Database type : 'CMS'
File Name : 'a.kdb'
Location :'/var/mqm/qmgrs/A/ssl/a'
 Next enter the password
 Open the signer certificates and click on add
 It opens a window in that enter
Certificate Name : 'b.arm'
Location : '/tmp/'
 Next enter the Label name
Label Name : 'ibmwebspheremqb'
 close the GUI
 Run 'gsk7ikm' command
gsk7ikm
 Open Key Database File 'b.kdb'
Key Database type : 'CMS'
File Name : 'b.kdb'
Location :'/var/mqm/qmgrs/B/ssl/b'
 Next enter the password
 Open the signer certificates and click on add
 It opens a window in that enter
Certificate Name : 'a.arm'
Location : '/tmp/'
 Next enter the Label name
Label Name : 'ibmwebspheremqa'
 close the GUI
 Run qmgr 'A'
 Inside qmgr 'A'
 Display channel status
DIS CHS(A.TO.B) ALL
 Check for the attributes
SSLCERTI(CN=vbwxpsp3-01,C=US)
SSLPEER(CN=vbwxpsp3-01,C=US)
 Similarly check it for qmgr 'B'
6. CLIENT-SERVER COMMUNICATION

In client-server communication a connection is established between client and server. Here the
client and server can be on the same host or two different hosts. The messages can be send
bidirectionally between client and server.

6.1 Setting up the server


 Create a Queue Manager 'A'
crtmqm A
 Start qmgr 'A'
strmqm A
 Run qmgr 'A'
runmqsc A
 Inside the qmgr 'A'
 Define Local Queue
DEFINE QL(A.LQ)
 Define Server channel
DEFINE CHL(SERVER.TO.A) CHLTYPE(SVRCONN) TRPTYPE(TCP)
MCAUSER('mqm')
 Start channel
START CHL(SERVER.TO.A)
 Define Listener
DEFINE LISTENER(LIST1) TRPTYPE(TCP) PORT(1414)
 Start Listener
START LISTENER(LIST1)
 END

6.2 Setting up the client


 Switch user to 'mqm'
 Edit '.bashrc' file
vi .bashrc
 append the following line into the file
MQSERVER=SERVER.TO.A/tcp/'Server IP Address(1414)';
export MQSERVER

6.3 Testing the communication:


 Make sure that the Queue Manager 'A' is running
 Now put the message on Server side
 Put the message
./amqsput A.LQ A
 At the Client side retrieve message
 Get the message
./amqsgetc A.LQ A
 Now put the message at the Client side
 Put the message
./amqsputc A.LQ A
 At the Server side retrieve the message
 Get the message
./amqsget A.LQ A

7. MULTI INSTANCE QUEUE MANAGER


Here we run an instance of a queue manager on two different servers. One instance is an active
instance and the other instance is in standby mode ready to take over from the active instance when it
fails. This increases availability.
7.1 Server1 configuration:
 Login to the terminal as root
 Install NFS using the following command
su –c 'yum install -y nfs-utils system-config-nfs'
 Start the NFS server using the command
systemctl start nfs-server.service
 Create a Directory 'MQHA'
mkdir /MQHA
 Inside 'MQHA' create two sub directories 'logs' and 'qmgrs'
mkdir /MQHA/logs /MQHA/qmgrs
 Change owner permissions
chown -R mqm:mqm /MQHA
 Change access permissions
chmod -R ug+rwx /MQHA
 Switch user as 'mqm'
 Create a Queue Manager 'QM1'
crtmqm -ld /MQHA/logs -md /MQHA/qmgrs -q QM1
 Open NFS application
Goto: Applications others NFS
 It opens a GUI
 In that GUI click on Add
 Next enter Directory name and IP address of the server2
Directory: /MQHA
Host : IP address of the server2
 In general options check the first two options
 In User access check the first option
 Start the NFS service using command
Systemctl start nfs-server.service
 Now display the queue manager information
dspmqinf –o command QM1
(it displays the following)
addmqinf –s QM1
-v Name=QM1
-v Directory=QM1
-v Prefix=/var/mqm
-v Datapath=/MQHA/qmgrs/QM1

7.2 Server2 configuration:


 Login to the terminal as root
 Install NFS using the following command
su –c 'yum install -y nfs-utils system-config-nfs'
 Start the NFS server using the command
systemctl start nfs-server.service
 Create a Directory 'MQHA'
mkdir /MQHA
 Change owner permissions
chown -R mqm:mqm /MQHA
 Change access permissions
chmod -R ug+rwx /MQHA
 Mount the shared folder of server1 in server2
mount Server1 IP address:/MQHA /MQHA
 Add queue manager information using command
addmqinf –s QM1
-v Name:QM1
-v Directory:QM1
-v Prefix:/var/mqm
-v Datapath:/MQHA/qmgrs/QM1
 To make the mount permanent edit ‘/etc/fstab’ file
vi /etc/fstab
(append the following line to the file)
Server2 IP Address:/MQHA /MQHA nfs rw 0 0

7.3 Testing:
 First start the QM1 in the Server1
strmqm –x QM1
 Now try to start QM1 on Server2.It will start as stand by
strmqm –x QM1
 When you stop the qmgr on Server1 then Server to will get active and will be in running state

8. BACKINGUP AND RESTORING A QUEUE MANAGER

Having a backup of a queue manager is essential because when hardware failure occurs we can
restore the lost data.
8.1 Backing up:
 Download MS03 file from internet
ms03_unix.tar.z
 Extract file ms03_unix.tar.z
 Create a file in tmp QM1.MQSC
 Change permissions if the file
chmod - R 777 QM1.MQSC
 run the command in downloads to backup qmgr
./saveqmgr.linux -m QM1 -f /tmp/QM1.MQSC
 start the queue manager
strmqm QM1

8.2 Restoring:
 first delete the qmgr
dltmqm QM1
 create the qmgr
crtmqm QM1
 start the qmgr
strmqm QM1
 to restore the backup file
runmqsc QM1 </tmp/QM1.MQSC
 check the queues or channels

9. PUBLISH AND SUBSCRIBE


First start the explorer using 'strmqcfg' command. It opens a GUI there create a new queue
manager.
Next create a topic by right-clicking on the topic option.

Enter the Topic name and the topic string.


Create a Local queue by right-clicking on the queue option
Create a subscriber

Select the topic from the list then click ok

Next enter the destination queue name.


Right-click on the topic and select the test publication from the menu

Enter the message to be published and press publish. Select queues next right click on the local queue
and select browse message. Similarly create more topics and more subscribers.

You might also like