此内容没有您所选择的语言版本。

28.6. Message Counters


Message counters can be used to obtain information on queues over time as HornetQ keeps a history of queue metrics.
They can be used to show trends on queues. For example, using the management API, it would be possible to query the number of messages in a queue at regular intervals. You could also view this information using the JMX Console, or use the core API (org.hornetq.api.core.management.MessageCounterInfo) to extract the information.
However, this would not be enough to know if the queue is used. The number of messages can remain constant because nobody is sending or receiving messages from the queue or because there are as many messages sent to the queue as messages consumed from it. The number of messages in the queue remains the same in both cases but its use is different.
Message counters provide additional information about the queues:
count
The total number of messages added to the queue since the server was started.
countDelta
The number of messages added to the queue since the last message counter update.
depth
The current number of messages in the queue.
depthDelta
The overall number of messages added or removed from the queue since the last message counter update. For example, if depthDelta is equal to -10 this means that overall 10 messages have been removed from the queue.
lastAddTimestamp
The time stamp of the last time a message was added to the queue.
udpateTimestamp
The time stamp of the last message counter update.

28.6.1. Configuring Message Counters

Message counters are disabled by default as they could have a negative effect on memory.
To enable message counters, you can set it to true in <JBOSS_HOME>/jboss-as/server/<PROFILE>/deploy/hornetq/hornetq-configuration.xml:
<message-counter-enabled>true</message-counter-enabled>
Copy to Clipboard Toggle word wrap
Message counters keep a history of the queue metrics (10 days by default) and sample all the queues at regular intervals (10 seconds by default). If message counters are enabled, these values should be configured to suit your messaging use case in <JBOSS_HOME>/jboss-as/server/<PROFILE>/deploy/hornetq/hornetq-configuration.xml:
<!-- keep history for a week -->
<message-counter-max-day-history>7</message-counter-max-day-history>        
<!-- sample the queues every minute (60000ms) -->
<message-counter-sample-period>60000</message-counter-sample-period>
Copy to Clipboard Toggle word wrap
Message counters can be retrieved using the Management API. For example, to retrieve message counters on a JMS Queue using JMX:
// retrieve a connection to HornetQ's MBeanServer
MBeanServerConnection mbsc = ...
JMSQueueControlMBean queueControl = (JMSQueueControl)MBeanServerInvocationHandler.newProxyInstance(mbsc,
   on,
   JMSQueueControl.class,
   false);
// message counters are retrieved as a JSON String                                                                                                      
String counters = queueControl.listMessageCounter();
// use the MessageCounterInfo helper class to manipulate message counters more easily
MessageCounterInfo messageCounter = MessageCounterInfo.fromJSON(counters);         
System.out.format("%s message(s) in the queue (since last sample: %s)\n",
   counter.getDepth(),
   counter.getDepthDelta());
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat