有几种方法可以监控 ActiveMQ。
例如,您可以使用Advisory-Messages。有一些指标可用,如
ActiveMQ.Advisory.SlowConsumer.Queue
ActiveMQ.Advisory.FastProducer.Topic
等等
要准确了解每个 JMX 的队列大小,请阅读
http://activemq.apache.org/how-do-i-find-the-size-of-a-queue.html
并尝试例如类似于我的代码片段的东西:
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://<server>:<port>/jmxrmi");
JMXConnector jmxConnector = JMXConnectorFactory.connect(url);
...
try
{
jmxConnector.connect();
MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
...
BrokerViewMBean brokerBean = MBeanServerInvocationHandler.newProxyInstance(connection, brokerBeanName, BrokerViewMBean.class, true);
System.out.println("Total message count:" + brokerBean.getTotalMessageCount());
...
}
...
如果您监控 QueueSize/TotalMessageCount,您可以对此做出反应。