英文:
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, "主机名");
hashtable.put(MQConstants.PORT_PROPERTY, 1414);
hashtable.put(MQConstants.CHANNEL_PROPERTY, "通道名");
hashtable.put(MQConstants.USER_ID_PROPERTY, "用户ID");
hashtable.put(MQConstants.PASSWORD_PROPERTY, "密码");
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)
...
MQCFST (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
...
MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
MQLONG Parameter: 204 (MQIA_SUB_COUNT)
MQLONG Value: 48 (0x00000030)
...
我期望通过上面的代码获取到订阅到groupTopic
的用户数量,但是MQConstants.MQIA_SUB_COUNT
的值始终是固定的48。我想知道我是否在错误地使用了PCFMessage,或者是否有其他方法可以获取主题的订阅者数量。
英文:
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.
答案1
得分: 2
像Mark在他的评论中说的那样,你应该执行MQSC命令DISPLAY TPSTATUS(xxxx) TYPE(TOPIC)
。我更倾向于显式设置PCF参数,以便我知道将会被返回的内容。
关于MQCMD_INQUIRE_TOPIC_STATUS的PCF命令编码,按照MQ知识中心中的规则进行:
因此,代码如下:
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++)
{
// 确保每个响应都是正常的
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
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论