2
votes

I want to create a Java standalone application for connecting via JMS to an MQ Queue Manager (not to be confused with a client). I want to create the JNDI resources independently and put everything in a JAR a run it to make some tests.

Is there any example that I can take to build this?

2
The JMS systems I know of (Joram, ActiveMQ and OpenMQ) all have Java API's that can be configured without using JNDI - a lot easier IMO for standalone apps. Is there any particular reason why you'd want JNDI anyways or doesn't Websphere have such a standalone API? - fvu
I'm having a problem using JNDI resources on WAS for connecting to an MQ Manager. I suspect something is going on with the server, so to narrow it down, I want to create an app that uses JNDI to use JMS interfaces to connect to this Queue Manager. If it works smoothly, then the server is the problem. Do you know any good tutorial or reference to create an app like that? - Xanathos
No, can't help you there, sorry. - fvu

2 Answers

2
votes

Little old but explains the steps: IBM WebSphere Developer Technical Journal: Developing a standalone Java application for WebSphere MQ http://www.ibm.com/developerworks/websphere/techjournal/0502_woolf/0502_woolf.html

Then to access the JNDI you need the thin client http://pic.dhe.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=%2Fcom.ibm.websphere.express.doc%2Finfo%2Fexp%2Fae%2Ftcli_developthin.html

There is also a sample in the client download JmsJndiProducer.java

1
votes

The Javadoc for the WebSphere MQ JMS classes can be found here. What you want to do is to create an instance of the com.ibm.mq.jms.MQConnectionFactory, com.ibm.mq.jms.MQQueueConnectionFactory or com.ibm.mq.jms.MQTopicConnectionFactory. Once you have an instance you can configure it using the various setters and then call one of the createConnection methods. A simple example would be:

MQConnectionFactory factory = new MQConnectionFactory();
factory.setQueueManager("myQmgr");
factory.setTransportType(WMQConstants.WMQ_CM_BINDINGS);

Connection conn = factory.createConnection();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue q = session.createQueue("myQ");
TextMessage msg = session.createTextMessage();
msg.setText("My message body");
MessageProducer sender = session.createProducer(q);