I'm using IBM-MQ, and I want to get the number of subscribers for a specific topic using 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);
The result for this is
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)
What I'm expecting is to get the number of users Susbscribed to groupTopic via the code above. But the value of MQConstants.MQIA_SUB_COUNT is It is always fixed at 48. I am wondering if I am using PCFMessage incorrectly or if there is another way to get the number of Subscribers for Topic.
Like Mark said in his comment, you should do the MQSC command DISPLAY TPSTATUS(xxxx) TYPE(TOPIC)
. I prefer to explicitly set PCF parameters so that I know what will be returned.
Coding for the PCF command of MQCMD_INQUIRE_TOPIC_STATUS, follow the rules in the MQ KnowLedge Center:
Hence, the code would be:
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);
}
}
So, the above PCF code is equivalent to the following MQSC command:
DISPLAY TPSTATUS(xxxx) TYPE(TOPIC) ALL
User contributions licensed under CC BY-SA 3.0