views:

855

answers:

3

How do i specify which queue manager to connect to in my system properties. Here is the code:

Properties properties = new Properties(); 
properties.setProperty("java.naming.factory.initial", "com.ibm.mq.jms.context.WMQInitialContextFactory");
properties.setProperty("java.naming.provider.url", "localhost:1414/SYSTEM.DEF.SVRCONN"); 

Context context = new InitialContext(properties); 
factory= (QueueConnectionFactory)context.lookup("TESTOUT"); 

context always gets TEST que only not able to connect to TESTOUT queue

A: 

Here's an example from the IBM website about how to setup Websphere Application Server (WAS) to use MQ as the mechanism for JMS.
http://www.ibm.com/developerworks/websphere/techjournal/0505_woolf/0505_woolf.html

Also IBM has a good redbook that outlines examples for how to do this if you are the message producer at:
http://www.redbooks.ibm.com/redbooks/pdfs/sg247128.pdf

There is also some good Java code examples at:
http://www.capitalware.biz/mq_code_java.html

Sorry....I don't have access to the code I did for this anymore or I'd give you some of my examples.

SOA Nerd
A: 

One can use the constructor of MQQueueManager to specify the name of the target queue manager, use the one with properties for connection information. Refer the following link for more details on properties:

http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/index.jsp?topic=/com.ibm.mq.csqzaw.doc/jm10910_.htm

Dr. Xray
+1  A: 

Hmmm...so many issues with the code snippet you posted, hard to know where to start.

Using the WMQInitialContectFactory does not seem like the place to start with MQ. It adds a layer of complexity you probably don't want at this stage. I'd suggest using Sun's fscontext and keep the managed objects in a local file. The initial context you are using is primarily used to make a shared JNDI repository for many users or applications, however it's not supported. My issue with it is that the program first has to connect to the queue manager in order to get a connection factory which...tells the program how to connect to the QMgr!

All those objects named SYSTEM.DEF.* or SYSTEM.AUTO.* should never be used for actual connections. They are templates that new objects inherit from. If they are useable you can't secure them or any objects created from them.

Either the snippet is incomplete or you are confusing the connection factory with the queue object. The post says you want the TESTOUT queue but the code has only a queue connection factory and no destination or queue object.

If you've installed WMQ server or client locally, you already have a bunch of good samples. The default location for these is C:\Program Files\IBM\WebSphere MQ\tools\jms\samples and they include both pub/sub and point-to-point examples. If you want an example that demonstrates creating the .bindings file, check out the article and sample code here: http://www.ibm.com/developerworks/websphere/techjournal/0610_woolf/0610_woolf.html The article explains some of the issues I just mentioned with the channels, client security, etc.

T.Rob