java - 使用Java获取MQ队列的ClusterName

标签 java ibm-mq

我正在构建一个连接到 MQQueueManager 并提取有关队列的信息的 java 应用程序。我能够获取 QueueTypeMaximumMessageLength 等数据。但是,我还想要队列可能所在的集群的名称。MQQueue 附带的函数没有为我提供此信息。在互联网上搜索后,我发现了一些指向这个方向的东西,但没有例子。

我的函数的一部分为我提供了MaximumDepth是:

    queueManager = makeConnection(host, portNo, qMgr, channelName);
    queue = queueManager.accessQueue(queueName, CMQC.MQOO_INQUIRE);
    maxQueueDepth = queue.getMaximumDepth();

(makeConnection 此处未显示,它是与 QueueManager 建立实际连接的函数;为了减少困惑,我还省略了 try/catch/finally)

如何获取没有 queue.getMaximumDepth() 等函数的 ClusterName 以及其他数据?

最佳答案

有两种方法可以获取有关队列的信息。

API 查询调用获取队列的操作状态。这包括 MQOpen 调用解析的名称或深度(如果队列是本地队列)等。许多 q.inquire 功能已被队列上的 getter 和 setter 函数取代。如果您不使用v8.0 client拥有最新功能,强烈建议您升级。它可以访问所有版本的 QMgr。

以下代码来自 Getting and setting attribute values in WebSphere MQ classes for Java

// inquire on a queue
final static int MQIA_DEF_PRIORITY = 6;
final static int MQCA_Q_DESC = 2013;
final static int MQ_Q_DESC_LENGTH = 64;

int[] selectors  = new int[2];
int[] intAttrs   = new int[1];
byte[] charAttrs = new byte[MQ_Q_DESC_LENGTH]

selectors[0] = MQIA_DEF_PRIORITY;
selectors[1] = MQCA_Q_DESC;

queue.inquire(selectors,intAttrs,charAttrs);

System.out.println("Default Priority = " + intAttrs[0]);
System.out.println("Description : " + new String(charAttrs,0));

对于不属于 API 查询调用一部分的内容,需要 PCF 命令。可编程命令格式(Programmable Command Format),通常缩写为PCF,是一种消息格式,用于将消息传递到命令队列以及从命令队列、事件队列等读取消息。

要使用 PCF 命令,调用应用程序必须通过 SYSTEM.ADMIN.COMMAND.QUEUE 上的 +put+dsp 进行授权关于被查询的对象。

IBM 提供示例代码。
在 Windows 上,请参阅:%MQ_FILE_PATH%\Tools\pcf\samples
在 UNIX 版本中,请参阅:/opt/mqm/samp/pcf/samples
这些位置可能会根据 MQ 的安装位置而有所不同。

请参阅:Handling PCF messages with IBM MQ classes for Java 。以下代码片段来自 PCF_DisplayActiveLocalQueues.java 示例程序。

  public static void DisplayActiveLocalQueues(PCF_CommonMethods pcfCM) throws PCFException,
      MQDataException, IOException {
    // Create the PCF message type for the inquire.
    PCFMessage pcfCmd = new PCFMessage(MQConstants.MQCMD_INQUIRE_Q);

    // Add the inquire rules.
    // Queue name = wildcard.
    pcfCmd.addParameter(MQConstants.MQCA_Q_NAME, "*");

    // Queue type = LOCAL.
    pcfCmd.addParameter(MQConstants.MQIA_Q_TYPE, MQConstants.MQQT_LOCAL);

    // Queue depth filter = "WHERE depth > 0".
    pcfCmd.addFilterParameter(MQConstants.MQIA_CURRENT_Q_DEPTH, MQConstants.MQCFOP_GREATER, 0);

    // Execute the command. The returned object is an array of PCF messages.
    PCFMessage[] pcfResponse = pcfCM.agent.send(pcfCmd);

    // For each returned message, extract the message from the array and display the
    // required information.
    System.out.println("+-----+------------------------------------------------+-----+");
    System.out.println("|Index|                    Queue Name                  |Depth|");
    System.out.println("+-----+------------------------------------------------+-----+");

    for (int index = 0; index < pcfResponse.length; index++) {
      PCFMessage response = pcfResponse[index];

      System.out.println("|"
          + (index + pcfCM.padding).substring(0, 5)
          + "|"
          + (response.getParameterValue(MQConstants.MQCA_Q_NAME) + pcfCM.padding).substring(0, 48)
          + "|"
          + (response.getParameterValue(MQConstants.MQIA_CURRENT_Q_DEPTH) + pcfCM.padding)
              .substring(0, 5) + "|");
    }

    System.out.println("+-----+------------------------------------------------+-----+");
    return;
  }
}

关于java - 使用Java获取MQ队列的ClusterName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33922650/

相关文章:

java - 锁定字符串

ibm-mq - IBM MQ 集群连接问题

java - WebSphere MQ : How to issue MQSC Commands using the Java API?

java - 更新 GAE 中的对象

java - Resteasy POST 未找到合适的构造函数

java - ActiveMQ JNDI 查找问题

queue - 如何在服务器端配置WebSphere MQ分发列表?

java - 如何在Eclipse中查找哪些类实现了多个接口(interface)?

java - MQ 客户端应用程序连接到客户端

java - PCFMessageAgent 如何处理断开连接?