Created
November 18, 2014 16:52
-
-
Save sachin-handiekar/6afbcdc28dbd3ead0626 to your computer and use it in GitHub Desktop.
Get ActiveMQ Queue Size using MBean (Spring JMX) - QueueSizeCounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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