Wednesday, 9 March 2011

Why is the "Total message retained" of a JMS Server different from the sum of the message queues/topics?

The actual meaning of "Total messages retained" is the "how many 'DataIMessages' the stcms server is currently using".

A "DataIMessage" includes all the different types of message that the stcms server uses. Thus includes JMS messages (all destinations), and also "Control" messages. You have probably seen topics like STCMS.Control or STCTemporaryTopic.1051196711431.1051192422022.1, which can be used internally by stcms for Control messages.

Every time the server creates a DataIMessage it increments the counter. When it destroys a message it decrements the counter. It is this count of DataIMessage which is reported as "Total messages retained". A DataIMessage might not get destroyed until the stcms performs "cleanup", which means the count may also include JMS messages which have been consumed.

After all user JMS messages have been consumed, and the stcms server has performed cleanup, the value of "Total messages retained" will be close to 0, but never actually 0 (because to obtain the server status, a message is sent to the Control Topic which the server will treat as a DataIMessage).