简体   繁体   中英

Java. How to connect to a remote Websphere MQ through a remote channel?

There is a system (IBM MDM) channel: SC.MDM.QM On this channel you have access to the managers of the bus. For example: M99.ESB.MDM2 which contains queu for messages: ESB.IBSO.TB49.MDM.ORG.IN

This is how we can put message to queu ( using RFHUtil utility):

Queue Manager Name(to connect to)

SC.MDM.QM/TCP/megri-t5.cgs.sbrf.ru(1414)

Queue Name

ESB.IBSO.TB49.MDM.ORG.IN

Remote Queue Manager Name (remote queues only)

M99.ESB.MDM2

But when i try to set same settings through java class:

public class SetWebsphere extends ConnectSettings {

    public static String queueName = "ESB.IBSO.TB49.MDM.ORG.IN";

    MQQueue defaultLocalQueue;
    MQQueueManager qManager;

     @SuppressWarnings({ "unchecked", "deprecation" })
     public void init(){
        //Set MQ connection credentials to MQ Envorinment.
         MQEnvironment.hostname = hostName;
         MQEnvironment.channel = channel;
         MQEnvironment.port = port;
         MQEnvironment.userID = user;

         MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);

         try {
             //initialize MQ manager.
            qManager = new MQQueueManager(qMngrStr);
        } catch (MQException e) {
            e.printStackTrace();
        }
    }

    @SuppressWarnings("deprecation")
       public void putAndGetMessage(String msg){
        int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE;
        try {
            defaultLocalQueue = qManager.accessQueue(queueName, openOptions);
            System.out.println(queueName); 

            MQMessage putMessage = new MQMessage();

            byte[] xk = msg.getBytes("UTF-8");
            putMessage.write(xk);
            putMessage.characterSet = 1208;
            //specify the message options...
            MQPutMessageOptions pmo = new MQPutMessageOptions(); 
            // accept 
            // put the message on the queue
            defaultLocalQueue.put(putMessage, pmo);

            System.out.println("Message is put on MQ.");

            defaultLocalQueue.close();
            qManager.disconnect();
        } catch (MQException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

public class ConnectSettings {

    static String qMngrStr;
    static String hostName;
    static String channel;
    static int port;

    public static void ConnectIFT() { 

        qMngrStr = "M99.ESB.MDM2";
        hostName = "megri-t5.cgs.sbrf.ru";
        port = 1414;
        channel = "SC.MDM.QM";
    }
}

The result is:

com.ibm.mq.MQException: MQJE001: Completion code '2', Reason'2058'.
    at com.ibm.mq.MQManagedConnectionJ11.<init>(MQManagedConnectionJ11.java:238)
    at com.ibm.mq.MQClientManagedConnectionFactoryJ11._createManagedConnection(MQClientManagedConnectionFactoryJ11.java:505)
    at com.ibm.mq.MQClientManagedConnectionFactoryJ11.createManagedConnection(MQClientManagedConnectionFactoryJ11.java:547)
    at com.ibm.mq.StoredManagedConnection.<init>(StoredManagedConnection.java:95)
    at com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManager.java:182)
    at com.ibm.mq.MQQueueManagerFactory.obtainBaseMQQueueManager(MQQueueManagerFactory.java:869)
    at com.ibm.mq.MQQueueManagerFactory.procure(MQQueueManagerFactory.java:761)
    at com.ibm.mq.MQQueueManagerFactory.constructQueueManager(MQQueueManagerFactory.java:712)
    at com.ibm.mq.MQQueueManagerFactory.createQueueManager(MQQueueManagerFactory.java:171)
    at com.ibm.mq.MQQueueManager.<init>(MQQueueManager.java:603)
    at ibmWebsphereMQ.SetWebsphere.init(SetWebsphere.java:67)
    at ibsoTestWebsphereMQ.IBSOTest.IBSOCreateCLient(IBSOTest.java:44)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:702)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:894)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1219)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:768)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1188)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1113)
    at org.testng.TestNG.run(TestNG.java:1025)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:109)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)

This code works fine if i'm trying to connect through Bus channel, for example (another server):

qMngrStr = "M99.ESB.MDM2";
hostName = "iskona-t2.cgs.sbrf.ru";
port = 1422;
channel = "SC.M99.ESB.MDM2";

The main question: How to put message to queue through system channel (SC.MDM.QM), using java code ?

Thanks In Advance!

Reason code 2058 points to queue manager name error. Are you sure you have provided the correct queue manager name in your code? You may be providing correct channel, host, port and transport type but the queue manager name is incorrect. So check if queue manager is correct.

When you want to use a QRemote there are two queue managers involved. There is the one to which you connect, and the one which hosts the destination queue. In your question you mention:

Remote Queue Manager Name (remote queues only)

M99.ESB.MDM2

Based on this I am guessing that M99.ESB.MDM2 is where the destination queue is hosted, and the QMgr to which you are connecting has another name.

  • For purposes of the CONNECT specify the QMgr where the TCP socket physically terminates.
  • When specifying a PUT to a remote queue, you can specify the name of the remote QMgr as well as the destination queue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM