ActiveMQ supports advisory messages which allows you to watch the system using regular JMS messages. Currently we have advisory messages that support

Advisory messages can be thought as some kind of administrative channel where you receive information regarding what is happening on your JMS provider along with what's happening with producers, consumers and destinations.

When you look at a broker via JMX you will see the advisory topics prefixed with ActiveMQ.Advisory..

Every Advisory has the message type 'Advisory' and some predefined message properties:

property name type description version
originBrokerId StringProperty the id of the broker where the advisory originated 5.x
originBrokerName StringProperty the name of the broker where the advisory originated 5.x
originBrokerURL StringProperty the first URL of the broker where the advisory originated 5.2

In addition, some messages carry a Command object - which carries more information for the advisory - e.g.

A subscription to each of the destination returns an ActiveMQMessage. Specific DataStructure objects (ie. ConsumerInfo, ProducerInfo,ConnectionInfo) can be retrieve via getDataStructure method of ActiveMQMessage.

For example:

...

    Destination advisoryDestination = AdvisorySupport.getProducerAdvisoryTopic(destination)
    MessageConsumer consumer = session.createConsumer(advisoryDestination);
    consumer.setMessageListener(this);
....
public void onMessage(Message msg){
    if (msg instanceof ActiveMQMessage){
        try {
             ActiveMQMessage aMsg =  (ActiveMQMessage)msg;
             ProducerInfo prod = (ProducerInfo) aMsg.getDataStructure();
        } catch (JMSException e) {
            log.error("Failed to process message: " + msg);
        }
    }
}

The following advisory topics are supported

Client based advisories

Tip

These are always generated

Advisory Topics Description properties Data Structure
ActiveMQ.Advisory.Connection Connection start & stop messages
ActiveMQ.Advisory.Producer.Queue Producer start & stop messages on a Queue String='producerCount' - the number of producers ProducerInfo
ActiveMQ.Advisory.Producer.Topic Producer start & stop messages on a Topic String='producerCount' - the number of producers ProducerInfo
ActiveMQ.Advisory.Consumer.Queue Consumer start & stop messages on a Queue String='consumerCount' - the number of Consumers ConsumerInfo
ActiveMQ.Advisory.Consumer.Topic Consumer start & stop messages on a Topic String='consumerCount' - the number of Consumers ConsumerInfo

Note that the consumer start/stop advisory messages also have a consumerCount header to indicate the number of active consumers on the destination when the advisory message was sent. This means you can use the following selector to be notified when there are no active consumers on a given destination...

consumerCount = 0

Destination and Message based advisories

Advisory Topics Description properties Data Structure default PolicyEntry property
ActiveMQ.Advisory.Queue Queue create & destroy null null true none
ActiveMQ.Advisory.Topic Topic create & destroy null null true none
ActiveMQ.Advisory.TempQueue Temporary Queue create & destroy null null true none
ActiveMQ.Advisory.TempTopic Temporary Topic create & destroy null null true none
ActiveMQ.Advisory.Expired.Queue Expired messages on a Queue String='orignalMessageId' - the expired id Message true none
ActiveMQ.Advisory.Expired.Topic Expired messages on a Topic String='orignalMessageId' - the expired id Message true none
ActiveMQ.Advisory.NoConsumer.Queue No consumer is available to process messages being sent on a Queue null Message false sendAdvisoryIfNoConsumers
ActiveMQ.Advisory.NoConsumer.Topic No consumer is available to process messages being sent on a Topic null Message false sendAdvisoryIfNoConsumers

Tip