Program to create a connection and access IBM MQ 7

2019-09-05 23:33发布

问题:

I have two programs

First Program :

qManager = serverConfig.qMgr;
            queueName=serverConfig.qName;
            this.serverType=serverType;
            //Factory Settings

            MQEnvironment.hostname =serverConfig.server;

            MQEnvironment.port = serverConfig.port;
            //
            MQEnvironment.channel = serverConfig.sChannel;

            MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);//Connection

// Create a connection to the queue manager

            //qMgr = new MQQueueManager(qManager);

Second Program :

                InitialDirContext ctx = null;
                Hashtable environment = new java.util.Hashtable();
                try{
                environment.put(Context.INITIAL_CONTEXT_FACTORY,QUEUE_CONTEXT);
                environment.put(Context.PROVIDER_URL,QUEUE_URL);
                ctx = new InitialDirContext(environment);

In the first program it asks for queue manager name but in the second program it doesn't require Queue Manager name. I need to replace the First program code with the second program.. Can anyone help me on this ..??

回答1:

Your second program is a JMS application and is using JNDI lookup to get connection details.

            environment.put(Context.INITIAL_CONTEXT_FACTORY,QUEUE_CONTEXT);
            environment.put(Context.PROVIDER_URL,QUEUE_URL);

            ctx = new InitialDirContext(environment);    
            connectionFactory = (ConnectionFactory) ctx.lookup(MYCF_LOOKUP_NAME);

QUEUE_CONTEXT is the connection factory name that's being looked up from QUEUE_URL. The QUEUE_CONTEXT will have all the connection details like the queue manager name, channel etc.