Introduction
In this example HowTo we see an example of the type of information you will learn about connecting WebSphere Application server 8 and WebSphere MQ (WAS 8.x and WMQ connectivity). This about 75% of one of the modules in my course title: WebSphere MQ 7.5 Administration Essentials course.
Here, we are going to use WebSphere MQ, a messaging system from IBM. WebSphere MQ is a robust product and supports the highest QoS i.e. delivering a message exactly once.
WebSphere Application Server supports connectivity to MQ through JMS interface, and due to this support, application developers can use the same set of JMS interfaces to send and receive messages i.e. they need not learn a new API.
Steps involved
First we will be installing WebSphere MQ product. Then we will be creating a Queue Manager and a Queue. In MQ, Queues are hosted using Queue Managers.
We need to reconfigure the wastest application to use a different connection factory that helps creating a connection to MQ. Also the wastest application will be used to post a message to a queue that resides on external MQ Queue Manager as opposed to the Queue that was hosted on the default JMS provider present within WAS.
IBM WebSphere MQ – Product Installation
MQ trial version can be downloaded from the following web page.
http://www.ibm.com/developerworks/downloads/ws/wmq
You will need an IBM user id to download. So you can use the same IBM user id that you used to download WAS. Select the flavour that is suitable for your Operating System. In this HowTo we are going to use
WebSphere MQ V7.1 Trial for Linux on x86 64bit Multilingual – CI510ML.tar.gz
The size of the download is 366 MB.
-
Download WebSphere MQ V7.1
-
Decompress the file CI510ML.tar.gz
You will find a script called mqlicense.sh under the base directory after the decompression. Execute this script to accept the license agreement.
-
Accept license agreement
sudo ./mqlicense.sh –accept
$ sudo ./mqlicense.sh -accept Licensed Materials – Property of IBM
5724-H72
(C) Copyright IBM Corporation 1994, 2011 All rights reserved.
US Government Users Restricted Rights – Use, duplication or disclosure
restricted by GSA ADP Schedule Contract with IBM Corp.
Agreement accepted: Proceed with install. |
-
Install MQ using the rpm package manager
rpm -ivh MQSeriesRuntime-7.1.0-0.x86_64.rpm rpm -ivh MQSeriesServer-7.1.0-0.x86_64.rpm rpm -ivh MQSeriesSamples-7.1.0-0.x86_64.rpm |
![]() |
Ubuntu users can refer to Appendix A for information on installing the rpm packages. |
A Unix user called mqm will be created on running the MQSeriesRuntime installable. All the MQ commands can be executed only as user mqm.
-
So you need to switch to mqm user now
$ su – mqm
![]() |
It is recommended to reset the password for mqm user at this point.
$ sudo passwd mqm Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully |
The first command that we can try after the installation is the dspmqver command.
-
Cd to /opt/mqm/bin directory
-
Issue the dspmqver command as shown below.
/opt/mqm/bin/dspmqver
We can see the product version as a result of executing this command.
mqm@steve-H67N-USB3-B3:/opt/mqm/bin$ ./dspmqver Name: WebSphere MQ Version: 7.1.0.0 Level: p000-L111024 BuildType: IKAP – (Production) Platform: WebSphere MQ for Linux (x86-64 platform) Mode: 64-bit O/S: Linux 3.0.0-15-generic InstName: Installation1 InstDesc: InstPath: /opt/mqm DataPath: /var/mqm Primary: No MaxCmdLevel: 710 |
Creating a Queue Manager
-
Create a Queue Manager called TESTMGR1 using crtmqm command
$ crtmqm TESTMGR1
mqm@steve-H67N-USB3-B3:/opt/mqm/bin$ crtmqm TESTMGR1 crtmqm: command not found mqm@steve-H67N-USB3-B3:/opt/mqm/bin$ ./crtmqm TESTMGR1 There are 90 days left in the trial period for this copy of WebSphere MQ. WebSphere MQ queue manager created. Directory ‘/var/mqm/qmgrs/TESTMGR1′ created. The queue manager is associated with installation ‘Installation1′. Creating or replacing default objects for queue manager ‘TESTMGR1′. Default objects statistics : 71 created. 0 replaced. 0 failed. Completing setup. Setup completed. |
-
Issue the dspmq command and check whether the Queue Manager is listed or not
mqm@steve-H67N-USB3-B3:/opt/mqm/bin$ ./dspmq QMNAME(TESTMGR1) STATUS(Ended immediately) |
-
Start the Queue Manager using strmqm command
./strmqm TESTMGR1
mqm@steve-H67N-USB3-B3:/opt/mqm/bin$ ./strmqm TESTMGR1 There are 90 days left in the trial period for this copy of WebSphere MQ. WebSphere MQ queue manager ‘TESTMGR1′ starting. The queue manager is associated with installation ‘Installation1′. 5 log records accessed on queue manager ‘TESTMGR1′ during the log replay phase. Log replay for queue manager ‘TESTMGR1′ complete. Transaction manager state recovered for queue manager ‘TESTMGR1′. WebSphere MQ queue manager ‘TESTMGR1′ started using V7.1.0.0. |
Creating a Queue
-
Open MQ scripting command line by giving the Queue Manager name
./runmqsc TESTMGR1
-
Create a Queue called “Q1LOCAL”
define qlocal(Q1LOCAL)
-
Quit the MQ command line by typing “end”
In the following example, user input is highlighted in Red colour
mqm@steve-H67N-USB3-B3:/opt/mqm/bin$ ./runmqsc TESTMGR1 5724-H72 (C) Copyright IBM Corp. 1994, 2011. ALL RIGHTS RESERVED. Starting MQSC for queue manager TESTMGR1. define qlocal(Q1LOCAL) 1 : define qlocal(Q1LOCAL) AMQ8006: WebSphere MQ queue created. end 2 : end One MQSC command read. No commands have a syntax error. All valid MQSC commands were processed. |
-
Verify the presence of the new queue using the following command.
$ echo “dis QLOCAL(*)” | ./runmqsc TESTMGR1 | grep -i Q1LOCAL QUEUE(Q1LOCAL) TYPE(QLOCAL) |
-
Add Listener definition using the following commands
./runmqsc TESTMGR1 DEFINE LISTENER(TESTMGR1.listener) TRPTYPE (TCP) PORT(1414) START LISTENER(TESTMGR1.listener) end |
Here we mention the transport type and port number for the listener.
The following example shows both the user input and the text emitted by MQ. User Input is highlighted.
mqm@steve-H67N-USB3-B3:/opt/mqm/bin$ ./runmqsc TESTMGR1 5724-H72 (C) Copyright IBM Corp. 1994, 2011. ALL RIGHTS RESERVED. Starting MQSC for queue manager TESTMGR1.
DEFINE LISTENER(TESTMGR1.listener) TRPTYPE(TCP) PORT(1414) 1 : DEFINE LISTENER(TESTMGR1.listener) TRPTYPE(TCP) PORT(1414) AMQ8626: WebSphere MQ listener created. START LISTENER(TESTMGR1.listener) 2 : START LISTENER(TESTMGR1.listener) AMQ8021: Request to start WebSphere MQ listener accepted. end 3 : end 2 MQSC commands read. No commands have a syntax error. All valid MQSC commands were processed. |
-
Now restart the Queue Manager using endmqm and strmqm commands as shown below
mqm@steve-H67N-USB3-B3:/opt/mqm/bin$ ./endmqm TESTMGR1 Quiesce request accepted. The queue manager will stop when all outstanding work is complete. mqm@steve-H67N-USB3-B3:/opt/mqm/bin$ ./strmqm TESTMGR1 There are 90 days left in the trial period for this copy of WebSphere MQ. WebSphere MQ queue manager ‘TESTMGR1′ ending. mqm@steve-H67N-USB3-B3:/opt/mqm/bin$ ./strmqm TESTMGR1 There are 90 days left in the trial period for this copy of WebSphere MQ. WebSphere MQ queue manager ‘TESTMGR1′ starting. The queue manager is associated with installation ‘Installation1′. 5 log records accessed on queue manager ‘TESTMGR1′ during the log replay phase. Log replay for queue manager ‘TESTMGR1′ complete. Transaction manager state recovered for queue manager ‘TESTMGR1′. WebSphere MQ queue manager ‘TESTMGR1′ started using V7.1.0.0. |
![]() |
If you give the start command strmqm before the Queue Manager stops, the start command just says Queue Manager <Queue Manager Name> ending as shown in the example above. |
-
Verify that the Listener started by issuing the ps command and grepping for mqlsr
mqm@steve-H67N-USB3-B3:/opt/mqm/bin$ ps -ef | grep mqlsr mqm 17392 17298 0 20:13 ? 00:00:00 /opt/mqm/bin/runmqlsr -r -m TESTMGR1 -t TCP -p 1414 |
Create a MQ Channel
A Channel is a logical communication link between a WMQ client and a WMQ Queue Manager. In a production environment the communication that happens through this channel has to be secured. The WebSphere MQ end configuration will be usually taken care by WebSphere MQ specialists and we will not be focusing on that topic.
-
Create a default channel
runmqsc TESTMGR1
DEFINE CHANNEL(SYSTEM.ADMIN.SVRCONN) +
CHLTYPE(SVRCONN) +
TRPTYPE(TCP) +
DESCR(‘WebSphere MQ Default Channel’) +
REPLACE
End
The example given below shows both user input and text emitted by MQ.
mqm@steve-H67N-USB3-B3:/opt/mqm/bin$ ./runmqsc TESTMGR1 5724-H72 (C) Copyright IBM Corp. 1994, 2011. ALL RIGHTS RESERVED. Starting MQSC for queue manager TESTMGR1.
DEFINE CHANNEL(SYSTEM.ADMIN.SVRCONN) + 1 : DEFINE CHANNEL(SYSTEM.ADMIN.SVRCONN) + CHLTYPE(SVRCONN) + : CHLTYPE(SVRCONN) + TRPTYPE(TCP) + : TRPTYPE(TCP) + DESCR(‘WebSphere MQ Default Channel’) + : DESCR(‘WebSphere MQ Default Channel’) + REPLACE : REPLACE AMQ8014: WebSphere MQ channel created. end 2 : end One MQSC command read. No commands have a syntax error. All valid MQSC commands were processed. |
Let us put a sample message using the sample program provided by WebSphere MQ and then get it back, just to verify the setup. This program was installed when we installed the package MQSeriesSamples-7.1.0-0.x86_64.rpm and will be available under /opt/mqm/samp/bin directory.
-
Execute amqsput, type the message text, press Enter key twice
The following example shows the user input and the text emitted by WMQ.
mqm@steve-H67N-USB3-B3:/opt/mqm/samp/bin$ ./amqsput Q1LOCAL TESTMGR1 Sample AMQSPUT0 start target queue is Q1LOCAL Hi, Test Message
Sample AMQSPUT0 end |
-
Execute amqsget
mqm@steve-H67N-USB3-B3:/opt/mqm/samp/bin$ ./amqsget Q1LOCAL TESTMGR1 Sample AMQSGET0 start message <Hi, Test Message> no more messages Sample AMQSGET0 end |
The Unix user account root has to be added to mqm group. This is required in our test environment to make things work. Since our focus is on WebSphere Application Server, let us do this. Note that this is not a recommended practice.
-
Add root user to mqm group
$ usermod -a -G mqm root
Now we are going to configure MQ security to modify access privileges to all the members of the mqm group. This will provide access to all the objects within the Queue Manager.
-
Execute setmqaut command as shown below
setmqaut -m TESTMGR1 -t qmgr -g mqm +all
mqm@steve-H67N-USB3-B3:/opt/mqm/bin$ ./setmqaut -m TESTMGR1 -t qmgr -g mqm +all The setmqaut command completed successfully. |
Creating a Queue Connection Factory
This step is similar to the one explained in Part 1.
-
Expand Resources in the left navigation pane of admin console
-
Expand JMS
-
Click on Queue connection factories
-
Select Cell scope
-
Click New button
Next “Select JMS resource provider” screen comes up. This is where we are going to select MQ as the messaging provider.
-
Select WebSphere MQ messaging provider option
Configure Basic Attributes screen is displayed as shown in the screen shot.
-
Enter “wmq_qcf_1″ for the name of QCF
-
Enter “jms/wmq_qcf_1″ for the JNDI name
-
Select Enter all the required information into this wizard option
-
Click Next button
In this case we give “TESTMGR1” which is the name of the Queue Manager we created earlier.
-
Enter the name of the Queue Manager
-
Click Next button
-
Give the hostname of the machine where MQ Queue Manager is running
-
Give the port number of the listener
-
Enter “SYSTEM.ADMIN.SVRCONN” in the Server connection channel field
-
Click Next button
Now the wizard provides an option to test the connection to WMQ.
-
Click on Test connection button
The test results are shown as seen in the screen shot.
-
Click Next button
Review the summary information.
-
Click Finish button
-
Click Save link
Now the new WMQ Queue Connection Factory is displayed in the table as shown in the screen shot.
|
Note that we have not used SiBus as the messaging provider is external to WAS |
Creating a Queue Destination
This queue created in WAS represents the queue that was created earlier in WMQ.
-
Expand Resources in the left navigation pane
-
Expand JMS
-
Click on Queues
-
Select Cell scope in the drop down
-
Click New button
-
Select WebSphere MQ messaging provider option
-
Click OK button
-
Give a name to the Queue in the Name field (This need not be the same as the MQ Queue name, i.e. Q1LOCAL)
-
Give a unique JNDI name to the Queue in the JNDI Name field
-
In the Queue Name field, provide the actual name of the Queue that was created in WMQ.
-
Click on OK button
-
Click Save link
We have completed the setup and a JEE application deployed in WAS can now start using the MQ messaging infrastructure. We can verify the setup using the test tool that we have.
|
Note that we have not used SiBus as the messaging provider is external to WAS. The message persistence is taken care by WebSphere MQ. |
To get the rest of this course, then have a look at http://www.themiddlewareshop.com/products/ and look for WebSphere MQ Training courses. |