Bootstrap FreeKB - IBM WebSphere - JMS create an IBM MQ connection factory
IBM WebSphere - JMS create an IBM MQ connection factory

Updated:   |  IBM WebSphere articles

Before setting up JMS (Java Message Service) components in WebSphere, you may first want to check out my MQ Getting Started article. "Connection factory" is the term that is used for how a Java application connects to a JMS queue, such as an IBM MQ queue or a RabbitMQ queue.

  1. In the WebSphere admin console, expand Resources > JMS.
  2. Select Connection factories if the Java application will be using javax.jms.ConnectionFactory and createConnection or Queue connection factories if the Java applications will be using javax.jms.QueueConnectionFactory and createQueueConnection.
  3. In the scope drop-down selector, select a scope.
  4. Select New.
  5. Choose WebSphere MQ Messaging Provider and select OK.

At Step 1: Configure basic attributes, give the connection factory name a name and JNDI.

At Step 2: Select connection method, select Enter all required information into this wizard and select Next.

At Step 2.1: Supply queue manager details, enter the name of the queue manager. If you have access to the IBM MQ server, the dspmq command can be used to display the queue managers on the IBM MQ server.

At Step 2.2: Enter connection details, if there is a single MQ server, select Enter host and port information in the form of separate hostname and port values and enter the hostname and port of the MQ server and the channel. If you are not sure the port and you have access to the MQ server, the runmqsc command can be used to determine the listener port. If you are not sure the name of the channel, the runmqsc command can be used to display the channels.

If there are two or more MQ servers, select Enter host and port information in the form of connection name list and enter the hostname and port in a comma separated list. 

Select Test Connection.

In this example, after selecting Test ConnectionA connection was successfully made to IBM MQ is returned. An error message may be returned if the MQ server requires a secured connection of SSL, as the SSL setup is done after the queue connection factory has been created.

 

Select Next > Finish > Save.

If you want to configure the connection factory to use SSL when connecting to IBM MQ, you will first need an SSL configuration in WebSphere that contains a trust store with the public certificate that can be used to establish the SSL handshake to IBM MQ. Check out my article on WebSphere SSL configuration. Let's say you have an SSL configuration named MQSSL.

 

And let's say the MQSSL SSL configuration CellDefaultTruststore.

 

In this scenario, in CellDefaultTruststore > Signer certificates, you'll want to ensure there is a public certificate that can be used to establish the SSL handshake to IBM MQ.

Select Resources > JMS > Connection factories and select the connection factory you created, checkmark Use SSL and select your SSL configuration.

 

Restart the dmgr so that the connection factory is bound to the dmgr. 

The connection factory should now be found in the ${WAS_INSTALL_ROOT}/profiles/your_profile/config/cells/your_cell/nodes/your_node/resources.xml file on the server. Likewise, the dmgr HPEL or SystemOut log will show the connection factory being bound to the dmgr.

WSVR0049I: Binding queue01cf as jms/queue01cf queue01cf

 

You should then be able to configure a Java application to use the connection factory to connect to IBM.

package my.pkg;

import java.util.Properties;
import javax.jms.JMSException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

// If you created a "Connection Factory" in WebSphere (not a Queue Connection Factory)
// then you will import Connection and ConnectionFactory
import javax.jms.Connection;
import javax.jms.ConnectionFactory;

// If you created a "Queue Connection Factory" in WebSphere (not a Connection Factory)
// then you will import QueueConnection and QueueConnectionFactory
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;

public class Main {
	public String main() throws NamingException, JMSException {
            
        int bootstrap_port = 9809;
        String jndi = "my/jndi";

        Properties env = new Properties ();
        env.put ( Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory" );
        env.put ( Context.PROVIDER_URL, "corbaloc:iiop:localhost:"+bootstrap_port );
        InitialContext jndi = new InitialContext (env);
           
        // If you created a "Connection Factory" in WebSphere (not a Queue Connection Factory)
        // then you will use ConnectionFactory here 
        ConnectionFactory qcf = (ConnectionFactory) jndi.lookup(jndi);
        Connection queueConn = qcf.createConnection();

        // If you created a "Queue Connection Factory" in WebSphere (not a Connection Factory)
        // then you will use QueueConnectionFactory here 
        QueueConnectionFactory qcf = (QueueConnectionFactory) jndi.lookup(jndi);
        QueueConnection queueConn = qcf.createQueueConnection();
            
        queueConn.start();
        queueConn.close();
        return "Successfully connected to IBM MQ";
    }
}

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


August 16 2021 by Nethaji
I gone through your articles. They were so nice, useful in daily work.

August 16 2021 by Jeremy (moderator)
Awesome, thanks for the kind words Nethaji. I am very happy to know my articles have helped you.

Add a Comment


Please enter 40721c in the box below so that we can be sure you are a human.