的信息。Advisory topics 都使用 ActiveMQ.Advisory.这个前缀,以下是目前支持的 topics:
Client based advisories
Advisory Topics Description
ActiveMQ.Advisory.Connection Connection start & stop messages
ActiveMQ.Advisory.Producer.Queue Producer start & stop messages on a Queue
ActiveMQ.Advisory.Producer.Topic Producer start & stop messages on a Topic
ActiveMQ.Advisory.Consumer.Queue Consumer start & stop messages on a Queue
ActiveMQ.Advisory.Consumer.Topic Consumer start & stop messages on a Topic
在消费者启动/停止的 Advisory Messages 的消息头中有个 consumerCount 属性,他用来指明目前 desination 上活跃的 consumer
的数量。
Destination and Message based advisories
Advisory Topics Description
ActiveMQ.Advisory.Queue Queue create & destroy
ActiveMQ.Advisory.Topic Topic create & destroy
ActiveMQ.Advisory.TempQueue Temporary Queue create & destroy
ActiveMQ.Advisory.TempTopic Temporary Topic create & destroy
ActiveMQ.Advisory.Expired.Queue Expired messages on a Queue
ActiveMQ.Advisory.Expired.Topic Expired messages on a Topic
ActiveMQ.Advisory.NoConsumer.Queue No consumer is available to process messages being sent on a Queue
ActiveMQ.Advisory.NoConsumer.Topic No consumer is available to process messages being sent on a Topic
以上的这些 destnations 都可以用来作为前缀,在其后面追加其它的重要信息,例如 topic、queue、clientID、producderID 和
consumerID 等。这令你可以利用 Wildcards 和 Selectors 来过滤 Advisory Messages(关于 Wildcard 和 Selector 会在稍后介绍)。
例 如 , 如 果 你 希 望 订 阅 FOO.BAR 这 个 queue 上 Consumer 的 start/stop 的 消 息 , 那 么 可 以 订 阅
ActiveMQ.Advisory.Consumer.Queue.FOO.BAR ; 如 果 希 望 订 阅 所 有 queue 上 的 start/stop 消 息 , 那 么 可 以 订 阅
ActiveMQ.Advisory.Consumer.Queue.> ; 如 果 希 望 订 阅 所 有 queue 或 者 topic 上 的 start/stop 消 息 , 那 么 可 以 订 阅
ActiveMQ.Advisory.Consumer. >。
org.apache.activemq.advisory.AdvisorySupport 类上有如下的 helper methods,用来在程序中得到 advisory destination objects。
Java 代码
1. AdvisorySupport.getConsumerAdvisoryTopic()
2. AdvisorySupport.getProducerAdvisoryTopic()
3. AdvisorySupport.getDestinationAdvisoryTopic()
4. AdvisorySupport.getExpiredTopicMessageAdvisoryTopic()
5. AdvisorySupport.getExpiredQueueMessageAdvisoryTopic()
6. AdvisorySupport.getNoTopicConsumersAdvisoryTopic()
7. AdvisorySupport.getNoQueueConsumersAdvisoryTopic()
以下是段使用 Advisory Messages 的程序代码:
Java 代码
1. Destination advisoryDestination = AdvisorySupport.getProducerAdvisoryTopic(destination)
2. MessageConsumer consumer = session.createConsumer(advisoryDestination);
3. consumer.setMessageListener(this);
4. ...
5. public void onMessage(Message msg){
6. if (msg instanceof ActiveMQMessage){
7. try {
8. ActiveMQMessage aMsg = (ActiveMQMessage)msg;
9. ProducerInfo prod = (ProducerInfo) aMsg.getDataStructure();
10. } catch (JMSException e) {
11. log.error("Failed to process message: " + msg);
12. }