IBM-MQ PCF 用于获取特定主题的订阅者数量

IBM-MQ PCF using to get subscriber count with a particular Topic

我正在使用 IBM-MQ,我想使用 PCFMessage 获取特定主题的订阅者数量

    MQQueueManager qmgr = null;
    PCFMessageAgent agent = null;
    
    Hashtable<String, Object> hashtable = new Hashtable<String,Object>();
    hashtable.put(MQConstants.HOST_NAME_PROPERTY,"HOST NAME");
    hashtable.put(MQConstants.PORT_PROPERTY,1414);
    hashtable.put(MQConstants.CHANNEL_PROPERTY,"CHANNEL NAME");
    hashtable.put(MQConstants.USER_ID_PROPERTY, "USER_ID");
    hashtable.put(MQConstants.PASSWORD_PROPERTY, "PASSWORD");
    
    agent = new PCFMessageAgent(qmgr);
    PCFMessage request = new PCFMessage(MQConstants.MQCMD_INQUIRE_TOPIC_STATUS);
    request.addParameter(MQConstants.MQCA_TOPIC_STRING, groupTopic);

结果是

    MQCFH (com.ibm.mq.headers.internal.store.ByteStore [encoding: 0x00000001, ccsid: 1208, size: 36] @813045649)
        MQLONG Type: 2 (0x00000002)
        MQLONG StrucLength: 36 (0x00000024)
        MQLONG Version: 3 (0x00000003)
        MQLONG Command: 183 (0x000000b7)
        MQLONG MsgSeqNumber: 1 (0x00000001)
        MQLONG Control: 1 (0x00000001)
        MQLONG CompCode: 0 (0x00000000)
        MQLONG Reason: 0 (0x00000000)
        MQLONG ParameterCount: 22 (0x00000016)
MQCFST (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 4 (0x00000004)
        MQLONG StrucLength: 40 (0x00000028)
        MQLONG Parameter: 2094 (MQCA_TOPIC_STRING)
        MQLONG CodedCharSetId: 1208 (0x000004b8)
        MQLONG StringLength: 19 (0x00000013)
        MQCHAR[] String: "{grouplist}"
MQCFST (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 4 (0x00000004)
        MQLONG StrucLength: 68 (0x00000044)
        MQLONG Parameter: 2105 (MQCA_ADMIN_TOPIC_NAME)
        MQLONG CodedCharSetId: 1208 (0x000004b8)
        MQLONG StringLength: 48 (0x00000030)
        MQCHAR[] String: "                                                "
MQCFST (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 4 (0x00000004)
        MQLONG StrucLength: 20 (0x00000014)
        MQLONG Parameter: 2029 (MQCA_CLUSTER_NAME)
        MQLONG CodedCharSetId: 1208 (0x000004b8)
        MQLONG StringLength: 0 (0x00000000)
        MQCHAR[] String: ""
MQCFST (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 4 (0x00000004)
        MQLONG StrucLength: 68 (0x00000044)
        MQLONG Parameter: 2110 (MQCA_COMM_INFO_NAME)
        MQLONG CodedCharSetId: 1208 (0x000004b8)
        MQLONG StringLength: 48 (0x00000030)
        MQCHAR[] String: "SYSTEM.DEFAULT.COMMINFO.MULTICAST               "
MQCFST (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 4 (0x00000004)
        MQLONG StrucLength: 68 (0x00000044)
        MQLONG Parameter: 2096 (MQCA_MODEL_DURABLE_Q)
        MQLONG CodedCharSetId: 1208 (0x000004b8)
        MQLONG StringLength: 48 (0x00000030)
        MQCHAR[] String: "SYSTEM.DURABLE.MODEL.QUEUE                      "
MQCFST (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 4 (0x00000004)
        MQLONG StrucLength: 68 (0x00000044)
        MQLONG Parameter: 2097 (MQCA_MODEL_NON_DURABLE_Q)
        MQLONG CodedCharSetId: 1208 (0x000004b8)
        MQLONG StringLength: 48 (0x00000030)
        MQCHAR[] String: "SYSTEM.NDURABLE.MODEL.QUEUE                     "
MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 3 (0x00000003)
        MQLONG StrucLength: 16 (0x00000010)
        MQLONG Parameter: 255 (MQIA_CLUSTER_PUB_ROUTE)
        MQLONG Value: 2 (0x00000002)
MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 3 (0x00000003)
        MQLONG StrucLength: 16 (0x00000010)
        MQLONG Parameter: 185 (MQIA_TOPIC_DEF_PERSISTENCE)
        MQLONG Value: 0 (0x00000000)
MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 3 (0x00000003)
        MQLONG StrucLength: 16 (0x00000010)
        MQLONG Parameter: 6 (MQIA_DEF_PRIORITY)
        MQLONG Value: 0 (0x00000000)
MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 3 (0x00000003)
        MQLONG StrucLength: 16 (0x00000010)
        MQLONG Parameter: 184 (MQIA_DEF_PUT_RESPONSE_TYPE)
        MQLONG Value: 1 (0x00000001)
MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 3 (0x00000003)
        MQLONG StrucLength: 16 (0x00000010)
        MQLONG Parameter: 175 (MQIA_DURABLE_SUB)
        MQLONG Value: 1 (0x00000001)
MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 3 (0x00000003)
        MQLONG StrucLength: 16 (0x00000010)
        MQLONG Parameter: 181 (MQIA_INHIBIT_PUB)
        MQLONG Value: 2 (0x00000002)
MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 3 (0x00000003)
        MQLONG StrucLength: 16 (0x00000010)
        MQLONG Parameter: 182 (MQIA_INHIBIT_SUB)
        MQLONG Value: 2 (0x00000002)
MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 3 (0x00000003)
        MQLONG StrucLength: 16 (0x00000010)
        MQLONG Parameter: 195 (MQIA_PM_DELIVERY)
        MQLONG Value: 2 (0x00000002)
MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 3 (0x00000003)
        MQLONG StrucLength: 16 (0x00000010)
        MQLONG Parameter: 196 (MQIA_NPM_DELIVERY)
        MQLONG Value: 3 (0x00000003)
MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 3 (0x00000003)
        MQLONG StrucLength: 16 (0x00000010)
        MQLONG Parameter: 1300 (MQIACF_RETAINED_PUBLICATION)
        MQLONG Value: 0 (0x00000000)
MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 3 (0x00000003)
        MQLONG StrucLength: 16 (0x00000010)
        MQLONG Parameter: 176 (MQIA_MULTICAST)
        MQLONG Value: 2 (0x00000002)
MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 3 (0x00000003)
        MQLONG StrucLength: 16 (0x00000010)
        MQLONG Parameter: 215 (MQIA_PUB_COUNT)
        MQLONG Value: 1 (0x00000001)
MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 3 (0x00000003)
        MQLONG StrucLength: 16 (0x00000010)
        MQLONG Parameter: 204 (MQIA_SUB_COUNT)
        MQLONG Value: 48 (0x00000030)
MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 3 (0x00000003)
        MQLONG StrucLength: 16 (0x00000010)
        MQLONG Parameter: 219 (MQIA_PUB_SCOPE)
        MQLONG Value: 0 (0x00000000)
MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 3 (0x00000003)
        MQLONG StrucLength: 16 (0x00000010)
        MQLONG Parameter: 218 (MQIA_SUB_SCOPE)
        MQLONG Value: 0 (0x00000000)
MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
        MQLONG Type: 3 (0x00000003)
        MQLONG StrucLength: 16 (0x00000010)
        MQLONG Parameter: 234 (MQIA_USE_DEAD_LETTER_Q)
        MQLONG Value: 2 (0x00000002)

我期望的是通过上面的代码获得订阅 groupTopic 的用户数。 但是 MQConstants.MQIA_SUB_COUNT 的值是 它始终固定为 48。我想知道我是否错误地使用了 PCFMessage,或者是否有其他方法可以获取主题的订阅者数量。

正如 Mark 在他的评论中所说,您应该执行 MQSC 命令 DISPLAY TPSTATUS(xxxx) TYPE(TOPIC)。我更喜欢显式设置 PCF 参数,以便我知道将返回什么。

MQCMD_INQUIRE_TOPIC_STATUS的PCF命令编码,遵循MQ KnowLedge Center中的规则:

因此,代码将是:

request = new PCFMessage(CMQCFC.MQCMD_INQUIRE_TOPIC_STATUS); 
request.addParameter(CMQC.MQCA_TOPIC_STRING, groupTopic);
request.addParameter(CMQCFC.MQIACF_TOPIC_STATUS_TYPE, CMQCFC.MQIACF_TOPIC_STATUS);
request.addParameter(CMQCFC.MQIACF_TOPIC_STATUS_ATTRS, new int [] { CMQCFC.MQIACF_ALL });

responses = agent.send(request);

for (int i = 0; i < responses.length; i++)
{
   // Make sure that each response is ok
   if ((responses[i]).getCompCode() == CMQC.MQCC_OK)
   {
      topicStr = responses[i].getStringParameterValue(CMQC.MQCA_TOPIC_STRING);
      topicName= responses[i].getStringParameterValue(CMQC.MQCA_ADMIN_TOPIC_NAME);
      durable  = responses[i].getIntParameterValue(CMQC.MQIA_DURABLE_SUB);
      persist  = responses[i].getIntParameterValue(CMQC.MQIA_TOPIC_DEF_PERSISTENCE);
      inh_Pub  = responses[i].getIntParameterValue(CMQC.MQIA_INHIBIT_PUB);
      inh_Sub  = responses[i].getIntParameterValue(CMQC.MQIA_INHIBIT_SUB);
      pubCount = responses[i].getIntParameterValue(CMQC.MQIA_PUB_COUNT);
      subCount = responses[i].getIntParameterValue(CMQC.MQIA_SUB_COUNT);
   }
}

所以,上面的PCF代码等同于下面的MQSC命令:

DISPLAY TPSTATUS(xxxx) TYPE(TOPIC) ALL