28.5.3. JMS メッセージ通知
HornetQ 通知は、JMS メッセージを使用して取得することもできます。
これは、Core API を使用して通知を受信することに似ていますが、重要な違いは、JMS がメッセージ (理想的にはトピック) を受信するために JMS 宛先が必要なことです。
JMS宛先を使用して管理通知を受信するには、
jms.queue
(JMS キューの場合) または jms.topic
(JMS トピックの場合) で開始するサーバーの管理通知アドレスを変更する必要があります。
<!-- notifications will be consumed from "notificationsTopic" JMS Topic --> <management-notification-address>jms.topic.notificationsTopic</management-notification-address>
通知トピックが作成されたら、それからメッセージを受け取ることができます。または以下のように
MessageListener
を設定できます。
Topic notificationsTopic = HornetQJMSClient.createTopic("notificationsTopic"); Session session = ... MessageConsumer notificationConsumer = session.createConsumer(notificationsTopic); notificationConsumer.setMessageListener(new MessageListener() { public void onMessage(Message notif) { System.out.println("------------------------"); System.out.println("Received notification:"); try { Enumeration propertyNames = notif.getPropertyNames(); while (propertyNames.hasMoreElements()) { String propertyName = (String)propertyNames.nextElement(); System.out.format(" %s: %s ", propertyName, notif.getObjectProperty(propertyName)); } } catch (JMSException e) { } System.out.println("------------------------"); } });