Java的。如何通过远程通道连接到远程Websphere MQ?

时间:2015-06-30 07:50:05

标签: java ibm-mq mdm

有一个系统(IBM MDM)频道: SC.MDM.QM 在这个频道上,您可以访问公交车的经理。 例如: M99.ESB.MDM2 ,其中包含邮件的队列: ESB.IBSO.TB49.MDM.ORG.IN

这就是我们如何将消息放入queu(使用RFHUtil 实用程序):

队列管理员名称(连接到)

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

队列名称

ESB.IBSO.TB49.MDM.ORG.IN

远程队列管理器名称(仅限远程队列)

M99.ESB.MDM2

但是当我尝试通过java类设置相同的设置时:

> sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.2 LTS

结果是:

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";
    }
}

例如,如果我尝试通过总线通道连接,则此代码可以正常工作 (另一台服务器):

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)

主要问题:如何使用java代码将消息通过系统通道(SC.MDM.QM)放入队列?

提前致谢!

2 个答案:

答案 0 :(得分:1)

原因代码2058指向队列管理器名称错误。您确定在代码中提供了正确的队列管理器名称吗?您可能提供了正确的通道,主机,端口和传输类型,但队列管理器名称不正确。所以检查队列管理器是否正确。

答案 1 :(得分:1)

当您想使用QRemote时,涉及两个队列管理器。您连接的是一个,以及承载目标队列的那个。在你的问题中你提到:

  

远程队列管理器名称(仅限远程队列)

     

M99.ESB.MDM2

基于此,我猜测M99.ESB.MDM2是托管目标队列的位置,并且您要连接的QMgr具有另一个名称。

  • 出于CONNECT的目的,指定TCP套接字物理终止的QMgr。
  • 为远程队列指定PUT时,您可以指定远程QMgr的名称以及目标队列。