使用java连接到ibm mq 7.5的问题

cyvaqqii  于 2021-07-09  发布在  Java
关注(0)|答案(2)|浏览(459)

我对ibmq非常陌生,我发现与mb相关的文档或书籍非常少,我找到的唯一一本是2004年写的“webspheremq使用java”。但现实世界已经改变了很多。在此基础上,我成功地在redhatlinux64位上安装并验证了mqserver7.5
我还创建了队列管理器 myqm1 ,队列 LQ.TEST ,通道 JAVA.CHANNEL 并在服务器上通过命令行进行了一些测试,以确保它们工作良好。但是,当我在windowsxp上安装mq客户机并编写以下java代码时,它总是抛出 exception:com.ibm.mq.MQException: MQJE001: Completion Code '2', Reason '2035' 我的代码:
导入com.ibm.mq.*;导入com.ibm.mq.constants.mqconstants;
/**简单示例程序/公共类mqsample{

// code identifier
static final String sccsid = "@(#) MQMBID sn=p000-L120604 su=_H-IvIK4nEeGko6IWl3MDhA pn=MQJavaSamples/wmqjava/MQSample.java";

// define the name of the QueueManager
private static final String qManager = "myqm1";
// and define the name of the Queue
private static final String qName = "LQ.TEST";

/**
 * Main entry point
 *
 * @param args - command line arguments (ignored)
 */
public static void main(String args[]) {
    try {
        MQEnvironment.hostname = "58.2.221.196"; 
        MQEnvironment.channel = "JAVA.CHANNEL"; 
        MQEnvironment.port = 1414;
        MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
        MQEnvironment.userID = "mqm"; 
        MQEnvironment.password = "mqm";
        MQEnvironment.CCSID = 1208;

        // Create a connection to the QueueManager
        System.out.println("Connecting to queue manager: " + qManager);
        MQQueueManager qMgr = new MQQueueManager(qManager);

        // Set up the options on the queue we wish to open
        int openOptions = MQConstants.MQOO_INPUT_AS_Q_DEF | MQConstants.MQOO_OUTPUT;

        // Now specify the queue that we wish to open and the open options
        System.out.println("Accessing queue: " + qName);
        MQQueue queue = qMgr.accessQueue(qName, openOptions);

        // Define a simple WebSphere MQ Message ...
        MQMessage msg = new MQMessage();
        // ... and write some text in UTF8 format
        msg.writeUTF("Hello, World!");

        // Specify the default put message options
        MQPutMessageOptions pmo = new MQPutMessageOptions();

        // Put the message to the queue
        System.out.println("Sending a message...");
        queue.put(msg, pmo);

        // Now get the message back again. First define a WebSphere MQ
        // message
        // to receive the data
        MQMessage rcvMessage = new MQMessage();

        // Specify default get message options
        MQGetMessageOptions gmo = new MQGetMessageOptions();

        // Get the message off the queue.
        System.out.println("...and getting the message back again");
        queue.get(rcvMessage, gmo);

        // And display the message text...
        String msgText = rcvMessage.readUTF();
        System.out.println("The message is: " + msgText);

        // Close the queue
        System.out.println("Closing the queue");
        queue.close();

        // Disconnect from the QueueManager
        System.out.println("Disconnecting from the Queue Manager");
        qMgr.disconnect();
        System.out.println("Done!");
    } catch (MQException ex) {
        ex.printStackTrace();
        System.out.println("A WebSphere MQ Error occured : Completion Code " + ex.completionCode
                + " Reason Code " + ex.reasonCode);

    } catch (java.io.IOException ex) {
        System.out.println("An IOException occured whilst writing to the message buffer: " + ex);
    }
    return;
} }

谁能给我点颜色看看吗?我完全崩溃了。

wnrlj8wa

wnrlj8wa1#

在mqv7.5中,默认情况下阻止对队列管理器的访问。您需要为您创建的通道创建通道身份验证记录, JAVA.CHANNEL 允许用户访问队列管理器。有关通道身份验证记录的详细信息,请访问此链接

kpbwa7wx

kpbwa7wx2#

为了扩展shashi的回答,由于wmqv7.1默认的chlauth规则阻止所有svrconn通道上的所有访问,并且它们阻止所有svrconn通道上的管理访问。如果你真的想连接到 JAVA.CHANNEL 作为 mqm 然后您需要覆盖这两种行为。
如果您确实愿意使用管理用户id允许到qmgr的未经验证的远程连接,那么您可以选择完全禁用chlauth规则。您可以通过发出 ALTER QMGR CHLAUTH(DISABLED) 命令输入 runmqsc 但是,这是非常不鼓励的,因为它使qmgr对使用wmq管理用户id的匿名远程代码执行开放。
建议的方法是使用非管理性的id。例如,如果您制作了一个名为 mquser 一个叫 mquser 然后您可以授予它在qmgr上连接和查询的权限,以及打开指定的队列以进行put、get、browse和inquire。由于id不是管理性的,所以在未经验证的通道上使用它相对安全。您可以更改代码以将id指定为 mquser 而不是 mqm 然后使用chlauth规则来允许连接。例如:

SET CHLAUTH('JAVA.CHANNEL') TYPE(USERMAP) +
    CLNTUSER('mquser') USERSRC(MAP) +
    MCAUSER('mquser') ACTION(ADD)

上面的规则告诉qmgr“当您看到来自 mquser id开启 JAVA.CHANNEL ,然后将mcauser设置为 mquser 允许连接。”
授予权限时,请记住对组而不是用户授予权限。例如,如果使用 setmqaut 使用 -g 选项而不是 -p 选项。如果授权错误有任何问题,可以使用事件消息轻松地解决这些问题。首先,使用 ALTER QMGR AUTHOREV(ENABLED) . 这将导致qmgr向 SYSTEM.ADMIN.QMGR.EVENT 排队。您可以使用supportpac mh05或supportpac ms0p来解析事件消息。对于任何给定的授权事件,消息告诉您请求访问的id、api调用(connect、open、close等)、调用所针对的对象以及使用的确切选项。
在wmqv7.1之前,webspheremq允许所有远程连接,甚至是匿名的管理连接。尽管这使您可以轻松地连接,但在当今更加恶劣的网络环境中,在qmgr的主机服务器上远程匿名执行代码的能力被视为不可接受的安全风险。因此,现在一个新的qmgr被设置为默认情况下不允许任何远程管理访问。作为管理员,这要求您显式禁用安全性以获取旧行为或显式提供安全访问。

相关问题