Date Created: Fri 11-Mar-2011

Related Document Categories:

Get my WebSphere MQ course here >> http://www.themiddlewareshop.com/products/


Creating a Queue Connection Factory and Queue for connectivity to MQ

Here are the resources used in the article:

runmqsetup.shrunmqsetup.shsetupMQ.mqscsetupMQ.mqsc

JMSTesterEAR.earJMSTesterEAR.ear

An application wishes to be able to post and receive message to MQ the application will pull messages put messages on MQ and will pull then off.

You need to define a resource reference (using the resource-ref tag) in web.xml and then figure out how to map that resource to a real resource in the web server. If you're using WebSphere app server then the deployment step will take care of that for you (you'll be prompted to map the web-app resource to a server resource.


In your code your JNDI call to get an Connection Factory object the JNDI lookup is going to be context.lookup("java:comp/env/jms/QCF").

In your code your JNDI call to get a queue object from the QCF object the JNDI lookup is going to context.lookup("java:comp/env/jms/Queue").


Then in the web.xml you would add the following:



<resource-ref>
<description>
</description>
<res-ref-name>jms/QCF</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>



<message-destination-ref>
<description>
</description>
<message-destination-ref-name>jms/Queue</message-destination-ref-name>
<message-destination-type>javax.jms.Queue</message-destination-type>
<message-destination-usage>ConsumesProduces</message-destination-usage>
<message-destination-link>jms/Queue</message-destination-link>
</message-destination-ref>

<message-destination>
<description>
</description>
<message-destination-name>jms/Queue</message-destination-name>
</message-destination>


When the application is deployed you can re-map these resources as they are defined as indirect JNDI resources. Re mapping is presented as an option in the application install wizard as WebSphere detects from the web.xml that indirect JNDI override is possible

If you DO NOT add the <resource-ref>, <message-destination-ref>, <message-destination> then you would have to create resources in WebSphere for the QCF and Queue that match exactly the names as defined in the code and this means that if you needed to install the application in an environment and the JNDI names you had used were already being used then your application would not work!

Here is the application working
http://<hostname>:<port>/JMSTester/

Port is usually 9080 is only one server exist, otherwise you need to look at the server ports.




You can see above the application is using jms/QCF for the queue connection factory and jms/Queue for the actual MQ queue. But our WebSphere as we will see below is not using these names.


Lets have a look at an installed application and show how we can update the resources anytime an override.






I want the application to use my resource called jms/QCF.LQTest. The application will still use jms/QCF, but WebSphere will use the target resource called jms/QCF.LQTest






The application will still use jms/Queue, but WebSphere will internally redirect to the resource target called jms/LQ.Test.

Script to create the Queue Manager and Queue

Create QM
crtmqm TSTQM1


Start QM
strmqm TSTQM1


Run script

runmqsc TSTQM1 < ./setupMQ.mqsc

script is called setupMQ.mqsc

********************************************************************/
* Create Listener */
********************************************************************/
DEFINE LISTENER (TSTQM1_1420) +
TRPTYPE (TCP) +
PORT (1420) +
CONTROL(QMGR) +
REPLACE
********************************************************************/
* Create Queues */
********************************************************************/

DEFINE QLOCAL('LQ.TEST') REPLACE +
DESCR('My Test Queue') +
* Persistent messages OK
DEFPSIST(YES) +
* Shareable
SHARE DEFSOPT(SHARED) +
* Maximum queue depth
MAXDEPTH(100000)


********************************************************************/
* Server - Channel */
********************************************************************/
DEFINE CHANNEL('SYSTEM.ADMIN.SVRCONN') +
CHLTYPE(SVRCONN) +
TRPTYPE(TCP) +
DESCR('Server connection for WebSphere') +
REPLACE

Creating a Queue Connection Factory
A QCF is used to know how to communicate with MQ as created by the mqsc script

Lest create the QCF and QUEUE. This SIB is not required for this!
















Now lets fix the auth error









Save and go back to QCF and set the authentication alias


Save


Creating a Queue (Destination)
Creating a JNDI resource for a MQ Queue

For you first scope use Cell, then once working you can create a node and or cluster scope

The actual queue name in MQ is LQ.TEST and is case-sensitive


Get my WebSphere MQ course here >> http://www.themiddlewareshop.com/products/

Steve Robinson - IBM Champion 2013

About Me

Steve Robinson has been working in IT for over 20 years and has provided solutions for many leading brands around the world. Steve specialises in JEE, DevOps and Thought Leadership.

In January 2013, I was awarded the prestigous 'IBM Champion' accolade.


  • Linked In
  • Twitter
  • About Me
  • Contact Me

Read my books?

IBM WebSphere Application Server 8.0 Administration Guide

IBM WebSphere Application Server 8.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

Courses

  • WebSphere Courses

Articles

WebSphere Categories

Other Categories