Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
596 views
in Technique[技术] by (71.8m points)

java - Program to create a connection and access IBM MQ 7

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 ..??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...