Reputation: 184
To get the message count from topic, I have invoked the WSO2 MB 3.1.0 AdminService api calls. It worked for queue but not for the topic. When invoking with topic, it doesn't give the correct count (it always gives 0)
(To show the message count in topic in WSO2 MB Management console, I have created an inbound endpoint with suspend state in WSO2 ESB and created a durable subscription to the topic)
https://localhost:9447/services/AndesAdminService.AndesAdminServiceHttpsSoap12Endpoint
Request body:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://wso2.org/carbon/andes/admin/xsd">
<soap:Header/>
<soap:Body>
<xsd:getMessageCount>
<!--Optional:-->
<xsd:destinationName>test-queue</xsd:destinationName>
<!--Optional:-->
<xsd:msgPattern>**queue**</xsd:msgPattern>
</xsd:getMessageCount>
</soap:Body>
</soap:Envelope>
url:https://localhost:9447/services/AndesAdminService.AndesAdminServiceHttpsSoap12Endpoint
Request body:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://wso2.org/carbon/andes/admin/xsd">
<soap:Header/>
<soap:Body>
<xsd:getMessageCount>
<!--Optional:-->
<xsd:destinationName>mytopic</xsd:destinationName>
<!--Optional:-->
<xsd:msgPattern>**topic**</xsd:msgPattern>
</xsd:getMessageCount>
</soap:Body>
</soap:Envelope>
I set the messagePattern as "topic" to get the message count in the topic. Is this not correct? If so whats the correct way of getting the message count in a topic using Admin services.
Reference: https://docs.wso2.com/display/MB310/Calling+Admin+Services+from+Apps
Upvotes: 1
Views: 235
Reputation: 11
There is no way to get message count of topics. Topics are supposed to be real time and there is no meaning to a message count in a "topic".
However, if you are looking for a message count remaining in a "durable topic", you can pass below information and get the message count.
queuename = carbon:{subscription ID} , msgPattern = queue
Relevant code
public long getMessageCount(String queueName, String msgPattern) throws MBeanException {
if (log.isDebugEnabled()) {
log.debug("Counting at queue : " + queueName);
}
long messageCount = 0;
try {
if (!DLCQueueUtils.isDeadLetterQueue(queueName)) {
if ("queue".equals(msgPattern)) {
messageCount = Andes.getInstance().getMessageCountOfQueue(queueName);
}
} else {
messageCount = Andes.getInstance().getMessageCountInDLC(queueName);
}
} catch (AndesException e) {
log.error(MESSAGE_COUNT_RETRIEVE_ERROR + queueName, e);
throw new MBeanException(e, MESSAGE_COUNT_RETRIEVE_ERROR + queueName);
}
return messageCount;
}
Upvotes: 0