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

huangapple go评论99阅读模式
英文:

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

问题

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

  1. MQQueueManager qmgr = null;
  2. PCFMessageAgent agent = null;
  3. Hashtable<String, Object> hashtable = new Hashtable<String, Object>();
  4. hashtable.put(MQConstants.HOST_NAME_PROPERTY, "主机名");
  5. hashtable.put(MQConstants.PORT_PROPERTY, 1414);
  6. hashtable.put(MQConstants.CHANNEL_PROPERTY, "通道名");
  7. hashtable.put(MQConstants.USER_ID_PROPERTY, "用户ID");
  8. hashtable.put(MQConstants.PASSWORD_PROPERTY, "密码");
  9. agent = new PCFMessageAgent(qmgr);
  10. PCFMessage request = new PCFMessage(MQConstants.MQCMD_INQUIRE_TOPIC_STATUS);
  11. request.addParameter(MQConstants.MQCA_TOPIC_STRING, groupTopic);

结果如下:

  1. MQCFH (com.ibm.mq.headers.internal.store.ByteStore [encoding: 0x00000001, ccsid: 1208, size: 36] @813045649)
  2. ...
  3. MQCFST (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  4. ...
  5. MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  6. MQLONG Parameter: 204 (MQIA_SUB_COUNT)
  7. MQLONG Value: 48 (0x00000030)
  8. ...

我期望通过上面的代码获取到订阅到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

  1. MQQueueManager qmgr = null;
  2. PCFMessageAgent agent = null;
  3. Hashtable&lt;String, Object&gt; hashtable = new Hashtable&lt;String,Object&gt;();
  4. hashtable.put(MQConstants.HOST_NAME_PROPERTY,&quot;HOST NAME&quot;);
  5. hashtable.put(MQConstants.PORT_PROPERTY,1414);
  6. hashtable.put(MQConstants.CHANNEL_PROPERTY,&quot;CHANNEL NAME&quot;);
  7. hashtable.put(MQConstants.USER_ID_PROPERTY, &quot;USER_ID&quot;);
  8. hashtable.put(MQConstants.PASSWORD_PROPERTY, &quot;PASSWORD&quot;);
  9. agent = new PCFMessageAgent(qmgr);
  10. PCFMessage request = new PCFMessage(MQConstants.MQCMD_INQUIRE_TOPIC_STATUS);
  11. request.addParameter(MQConstants.MQCA_TOPIC_STRING, groupTopic);

The result for this is

  1. MQCFH (com.ibm.mq.headers.internal.store.ByteStore [encoding: 0x00000001, ccsid: 1208, size: 36] @813045649)
  2. MQLONG Type: 2 (0x00000002)
  3. MQLONG StrucLength: 36 (0x00000024)
  4. MQLONG Version: 3 (0x00000003)
  5. MQLONG Command: 183 (0x000000b7)
  6. MQLONG MsgSeqNumber: 1 (0x00000001)
  7. MQLONG Control: 1 (0x00000001)
  8. MQLONG CompCode: 0 (0x00000000)
  9. MQLONG Reason: 0 (0x00000000)
  10. MQLONG ParameterCount: 22 (0x00000016)
  11. MQCFST (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  12. MQLONG Type: 4 (0x00000004)
  13. MQLONG StrucLength: 40 (0x00000028)
  14. MQLONG Parameter: 2094 (MQCA_TOPIC_STRING)
  15. MQLONG CodedCharSetId: 1208 (0x000004b8)
  16. MQLONG StringLength: 19 (0x00000013)
  17. MQCHAR[] String: &quot;{grouplist}&quot;
  18. MQCFST (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  19. MQLONG Type: 4 (0x00000004)
  20. MQLONG StrucLength: 68 (0x00000044)
  21. MQLONG Parameter: 2105 (MQCA_ADMIN_TOPIC_NAME)
  22. MQLONG CodedCharSetId: 1208 (0x000004b8)
  23. MQLONG StringLength: 48 (0x00000030)
  24. MQCHAR[] String: &quot; &quot;
  25. MQCFST (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  26. MQLONG Type: 4 (0x00000004)
  27. MQLONG StrucLength: 20 (0x00000014)
  28. MQLONG Parameter: 2029 (MQCA_CLUSTER_NAME)
  29. MQLONG CodedCharSetId: 1208 (0x000004b8)
  30. MQLONG StringLength: 0 (0x00000000)
  31. MQCHAR[] String: &quot;&quot;
  32. MQCFST (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  33. MQLONG Type: 4 (0x00000004)
  34. MQLONG StrucLength: 68 (0x00000044)
  35. MQLONG Parameter: 2110 (MQCA_COMM_INFO_NAME)
  36. MQLONG CodedCharSetId: 1208 (0x000004b8)
  37. MQLONG StringLength: 48 (0x00000030)
  38. MQCHAR[] String: &quot;SYSTEM.DEFAULT.COMMINFO.MULTICAST &quot;
  39. MQCFST (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  40. MQLONG Type: 4 (0x00000004)
  41. MQLONG StrucLength: 68 (0x00000044)
  42. MQLONG Parameter: 2096 (MQCA_MODEL_DURABLE_Q)
  43. MQLONG CodedCharSetId: 1208 (0x000004b8)
  44. MQLONG StringLength: 48 (0x00000030)
  45. MQCHAR[] String: &quot;SYSTEM.DURABLE.MODEL.QUEUE &quot;
  46. MQCFST (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  47. MQLONG Type: 4 (0x00000004)
  48. MQLONG StrucLength: 68 (0x00000044)
  49. MQLONG Parameter: 2097 (MQCA_MODEL_NON_DURABLE_Q)
  50. MQLONG CodedCharSetId: 1208 (0x000004b8)
  51. MQLONG StringLength: 48 (0x00000030)
  52. MQCHAR[] String: &quot;SYSTEM.NDURABLE.MODEL.QUEUE &quot;
  53. MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  54. MQLONG Type: 3 (0x00000003)
  55. MQLONG StrucLength: 16 (0x00000010)
  56. MQLONG Parameter: 255 (MQIA_CLUSTER_PUB_ROUTE)
  57. MQLONG Value: 2 (0x00000002)
  58. MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  59. MQLONG Type: 3 (0x00000003)
  60. MQLONG StrucLength: 16 (0x00000010)
  61. MQLONG Parameter: 185 (MQIA_TOPIC_DEF_PERSISTENCE)
  62. MQLONG Value: 0 (0x00000000)
  63. MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  64. MQLONG Type: 3 (0x00000003)
  65. MQLONG StrucLength: 16 (0x00000010)
  66. MQLONG Parameter: 6 (MQIA_DEF_PRIORITY)
  67. MQLONG Value: 0 (0x00000000)
  68. MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  69. MQLONG Type: 3 (0x00000003)
  70. MQLONG StrucLength: 16 (0x00000010)
  71. MQLONG Parameter: 184 (MQIA_DEF_PUT_RESPONSE_TYPE)
  72. MQLONG Value: 1 (0x00000001)
  73. MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  74. MQLONG Type: 3 (0x00000003)
  75. MQLONG StrucLength: 16 (0x00000010)
  76. MQLONG Parameter: 175 (MQIA_DURABLE_SUB)
  77. MQLONG Value: 1 (0x00000001)
  78. MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  79. MQLONG Type: 3 (0x00000003)
  80. MQLONG StrucLength: 16 (0x00000010)
  81. MQLONG Parameter: 181 (MQIA_INHIBIT_PUB)
  82. MQLONG Value: 2 (0x00000002)
  83. MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  84. MQLONG Type: 3 (0x00000003)
  85. MQLONG StrucLength: 16 (0x00000010)
  86. MQLONG Parameter: 182 (MQIA_INHIBIT_SUB)
  87. MQLONG Value: 2 (0x00000002)
  88. MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  89. MQLONG Type: 3 (0x00000003)
  90. MQLONG StrucLength: 16 (0x00000010)
  91. MQLONG Parameter: 195 (MQIA_PM_DELIVERY)
  92. MQLONG Value: 2 (0x00000002)
  93. MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  94. MQLONG Type: 3 (0x00000003)
  95. MQLONG StrucLength: 16 (0x00000010)
  96. MQLONG Parameter: 196 (MQIA_NPM_DELIVERY)
  97. MQLONG Value: 3 (0x00000003)
  98. MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  99. MQLONG Type: 3 (0x00000003)
  100. MQLONG StrucLength: 16 (0x00000010)
  101. MQLONG Parameter: 1300 (MQIACF_RETAINED_PUBLICATION)
  102. MQLONG Value: 0 (0x00000000)
  103. MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  104. MQLONG Type: 3 (0x00000003)
  105. MQLONG StrucLength: 16 (0x00000010)
  106. MQLONG Parameter: 176 (MQIA_MULTICAST)
  107. MQLONG Value: 2 (0x00000002)
  108. MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  109. MQLONG Type: 3 (0x00000003)
  110. MQLONG StrucLength: 16 (0x00000010)
  111. MQLONG Parameter: 215 (MQIA_PUB_COUNT)
  112. MQLONG Value: 1 (0x00000001)
  113. MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  114. MQLONG Type: 3 (0x00000003)
  115. MQLONG StrucLength: 16 (0x00000010)
  116. MQLONG Parameter: 204 (MQIA_SUB_COUNT)
  117. MQLONG Value: 48 (0x00000030)
  118. MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  119. MQLONG Type: 3 (0x00000003)
  120. MQLONG StrucLength: 16 (0x00000010)
  121. MQLONG Parameter: 219 (MQIA_PUB_SCOPE)
  122. MQLONG Value: 0 (0x00000000)
  123. MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  124. MQLONG Type: 3 (0x00000003)
  125. MQLONG StrucLength: 16 (0x00000010)
  126. MQLONG Parameter: 218 (MQIA_SUB_SCOPE)
  127. MQLONG Value: 0 (0x00000000)
  128. MQCFIN (com.ibm.mq.headers.internal.ReflectingStore [encoding: 0x00000001, ccsid: 1208])
  129. MQLONG Type: 3 (0x00000003)
  130. MQLONG StrucLength: 16 (0x00000010)
  131. MQLONG Parameter: 234 (MQIA_USE_DEAD_LETTER_Q)
  132. 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知识中心中的规则进行:

因此,代码如下:

  1. request = new PCFMessage(CMQCFC.MQCMD_INQUIRE_TOPIC_STATUS);
  2. request.addParameter(CMQC.MQCA_TOPIC_STRING, groupTopic);
  3. request.addParameter(CMQCFC.MQIACF_TOPIC_STATUS_TYPE, CMQCFC.MQIACF_TOPIC_STATUS);
  4. request.addParameter(CMQCFC.MQIACF_TOPIC_STATUS_ATTRS, new int [] { CMQCFC.MQIACF_ALL });
  5. responses = agent.send(request);
  6. for (int i = 0; i < responses.length; i++)
  7. {
  8. // 确保每个响应都是正常的
  9. if ((responses[i]).getCompCode() == CMQC.MQCC_OK)
  10. {
  11. topicStr = responses[i].getStringParameterValue(CMQC.MQCA_TOPIC_STRING);
  12. topicName= responses[i].getStringParameterValue(CMQC.MQCA_ADMIN_TOPIC_NAME);
  13. durable = responses[i].getIntParameterValue(CMQC.MQIA_DURABLE_SUB);
  14. persist = responses[i].getIntParameterValue(CMQC.MQIA_TOPIC_DEF_PERSISTENCE);
  15. inh_Pub = responses[i].getIntParameterValue(CMQC.MQIA_INHIBIT_PUB);
  16. inh_Sub = responses[i].getIntParameterValue(CMQC.MQIA_INHIBIT_SUB);
  17. pubCount = responses[i].getIntParameterValue(CMQC.MQIA_PUB_COUNT);
  18. subCount = responses[i].getIntParameterValue(CMQC.MQIA_SUB_COUNT);
  19. }
  20. }

因此,上述PCF代码等同于以下MQSC命令:

  1. 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:

  1. request = new PCFMessage(CMQCFC.MQCMD_INQUIRE_TOPIC_STATUS);
  2. request.addParameter(CMQC.MQCA_TOPIC_STRING, groupTopic);
  3. request.addParameter(CMQCFC.MQIACF_TOPIC_STATUS_TYPE, CMQCFC.MQIACF_TOPIC_STATUS);
  4. request.addParameter(CMQCFC.MQIACF_TOPIC_STATUS_ATTRS, new int [] { CMQCFC.MQIACF_ALL });
  5. responses = agent.send(request);
  6. for (int i = 0; i &lt; responses.length; i++)
  7. {
  8. // Make sure that each response is ok
  9. if ((responses[i]).getCompCode() == CMQC.MQCC_OK)
  10. {
  11. topicStr = responses[i].getStringParameterValue(CMQC.MQCA_TOPIC_STRING);
  12. topicName= responses[i].getStringParameterValue(CMQC.MQCA_ADMIN_TOPIC_NAME);
  13. durable = responses[i].getIntParameterValue(CMQC.MQIA_DURABLE_SUB);
  14. persist = responses[i].getIntParameterValue(CMQC.MQIA_TOPIC_DEF_PERSISTENCE);
  15. inh_Pub = responses[i].getIntParameterValue(CMQC.MQIA_INHIBIT_PUB);
  16. inh_Sub = responses[i].getIntParameterValue(CMQC.MQIA_INHIBIT_SUB);
  17. pubCount = responses[i].getIntParameterValue(CMQC.MQIA_PUB_COUNT);
  18. subCount = responses[i].getIntParameterValue(CMQC.MQIA_SUB_COUNT);
  19. }
  20. }

So, the above PCF code is equivalent to the following MQSC command:

  1. DISPLAY TPSTATUS(xxxx) TYPE(TOPIC) ALL

huangapple
  • 本文由 发表于 2020年9月15日 17:15:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/63898748.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定