Skip to content

Instantly share code, notes, and snippets.

@hyperius
Forked from sachin-handiekar/QueueSizeCounter.java
Created October 17, 2019 15:34
Show Gist options
  • Save hyperius/459e85b5c14b8434fa4f59ba39cfac5f to your computer and use it in GitHub Desktop.
Save hyperius/459e85b5c14b8434fa4f59ba39cfac5f to your computer and use it in GitHub Desktop.
Get ActiveMQ Queue Size using MBean (Spring JMX) - QueueSizeCounter.java
package com.sample;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import org.apache.log4j.Logger;
public class QueueSizeCounter {
private MBeanServerConnection mBeanServerConnection;
private Logger logger = Logger.getLogger(QueueSizeCounter.class);
public Long getQueueSize(String queueName) {
Long queueSize = null;
try {
ObjectName objectNameRequest = new ObjectName(
"org.apache.activemq:BrokerName=localhost,Type=Queue,Destination=" + queueName);
queueSize = (Long) mBeanServerConnection.getAttribute(objectNameRequest, "QueueSize");
return queueSize;
}
catch (Exception e) {
logger.error(e.getMessage());
}
return queueSize;
}
public void setmBeanServerConnection(MBeanServerConnection mBeanServerConnection) {
this.mBeanServerConnection = mBeanServerConnection;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment