0
votes

I am new to MQ and JNDI and I looking for some simple sample Java code that resolves my WAS JMS configuration and can write to and read from two Message Queues.

specifically I would like JAVA code to:

  • run code on IBM WebSphere Application Server Network Deployment (WAS ND 8.5.5)
  • write to, and read from, 2 IBM Integration Bus (IIB) Message Queues on an external system

  • In WAS I configured JMS resources as follows:

    • for the connection factory - gave it a JNDI name of "jms/MQCONN.FACTORY"
    • for the queue #1 - gave it a JNDI name of "jms/MQUEUE1.DEST"
    • for the queue #2 - gave is a JNDI name of "jms/MQUEUE2.DEST"

I set up JAAS - J2C authentication data credentials.

Note: I was unable to test the connection to MQ for connection factory, because the security settings are added to after the wizard completes and the you can only test from the wizard. I believe the WAS configuration is correct including the credentials.

I especially do not understand how to code the JNDI part (i.e. How to store the environment variable that tells JNDI which initial context to use, and where to find the provider.)

Grateful for any assistance!

2
There's no such thing as far as I'm aware as an IIB Message Queue. Do you mean an IBM MQ queue? IIB can interact with MQ's queues, but it doesn't have queues itself.Tim McCormick

2 Answers

0
votes

Sibyl , Once you have configured these Managed Objects (QueueConnectionFactory . Queue) , you should be able to lookup these from code that you can deploy on the application server.

You will have to get

a) InitialContext (when you deploy a ear on the server , you can use the default constructor)

b) Lookup queue connection factory (context.lookup(xxx))

c) Lookup queue (context.lookup(yyyy))

d) Create a message producer

e) Create a Queue Session , text message and send the message directly

You can get some more idea here (http://www.webspheretools.com/sites/webspheretools.nsf/docs/Creating%20a%20Queue%20Connection%20Factory%20and%20Queue%20for%20connectivity%20to%20MQ)

Basically post configuration it is a lot of Boilerplate JMS coding

0
votes

Here is little help for you. You don't need to provide extra configuration after creating resources in WAS.

Queue myQueue;
QueueConnectionFactory myQueueFactory;
QueueConnection connection = null;
QueueSession session = null;

try{
    InitialContext jndi = new InitialContext();
    myQueueFactory = (QueueConnectionFactory) jndi.lookup("jms/MQCONN.FACTORY");
    myQueue = (Queue) jndi.lookup("jms/MQUEUE1.DEST");

    connection=myQueueFactory.createQueueConnection();

    session = connection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);

    QueueSender sender = session.createSender(myQueue);
    connection.start();
    TextMessage textMessage = session.createTextMessage(event);
    textMessage.setStringProperty("messageType", "file");
    sender.send(textMessage);

    sender.close();

    if (session != null) {
        session.close();
    }

    if (connection != null) {
        connection.close();
    }
} catch (JMSException e) {
    e.printStackTrace();
}