[hornetq-commits] JBoss hornetq SVN: r8994 - in trunk: examples/jms/management-notifications and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Mar 29 05:35:53 EDT 2010


Author: jmesnil
Date: 2010-03-29 05:35:53 -0400 (Mon, 29 Mar 2010)
New Revision: 8994

Modified:
   trunk/docs/user-manual/en/management.xml
   trunk/examples/jms/management-notifications/readme.html
   trunk/examples/jms/management-notifications/server0/hornetq-configuration.xml
   trunk/examples/jms/management-notifications/server0/hornetq-jms.xml
   trunk/examples/jms/management-notifications/src/org/hornetq/jms/example/ManagementNotificationExample.java
Log:
management notification example

* use a JMS Topic instead of a Queue to receive notifications
* fixed out of date management documentation

Modified: trunk/docs/user-manual/en/management.xml
===================================================================
--- trunk/docs/user-manual/en/management.xml	2010-03-29 08:39:05 UTC (rev 8993)
+++ trunk/docs/user-manual/en/management.xml	2010-03-29 09:35:53 UTC (rev 8994)
@@ -772,14 +772,18 @@
          <para>HornetQ's notifications can also be received using JMS messages.</para>
          <para>It is similar to receiving notifications using Core API but an important difference
             is that JMS requires a JMS Destination to receive the messages (preferably a
-            Topic):</para>
+            Topic).</para>
+         <para>To use a JMS Destination to receive management notifications, you must change the server's
+            management notification address to start with <literal>jms.queue</literal> if it is a JMS Queue
+            or <literal>jms.topic</literal> if it is a JMS Topic:</para>
          <programlisting>
-   Topic notificationsTopic = HornetQJMSClient.createHornetQTopic("hornetq.notifications", "hornetq.notifications");
+            &lt;!-- notifications will be consumed from "notificationsTopic" JMS Topic --> 
+            &lt;management-notification-address&gt;jms.topic.notificationsTopic&lt;/management-notification-address&gt;
          </programlisting>
          <para>Once the notification topic is created, you can receive messages from it or set a
                <literal>MessageListener</literal>:</para>
          <programlisting>
-   Topic notificationsTopic = HornetQJMSClient.createHornetQTopic("hornetq.notifications", "hornetq.notifications");
+   Topic notificationsTopic = HornetQJMSClient.createTopic("notificationsTopic");
 
    Session session = ...
    MessageConsumer notificationConsumer = session.createConsumer(notificationsTopic);

Modified: trunk/examples/jms/management-notifications/readme.html
===================================================================
--- trunk/examples/jms/management-notifications/readme.html	2010-03-29 08:39:05 UTC (rev 8993)
+++ trunk/examples/jms/management-notifications/readme.html	2010-03-29 09:35:53 UTC (rev 8994)
@@ -19,31 +19,22 @@
 
      <p>HornetQ can configured to send JMS messages when management notifications are emitted on the server.</p>
      <p>By default, the management name is called <code>hornetq.notifications</code> but this can be configured in <a href="server0/hornetq-configuration.xml">hornetq-configuration.xml</a>.
-        For this example, we will set it to <code>example.notifications</code>.</p>
+        For this example, we will set it to <code>jms.topic.notificationsTopic</code> to be able to receive notifications from a JMS Topic.</p>
       <pre class="prettyprint">
-         <code>&lt;management-notification-address&gt;example.notifications&lt;/management-notification-address&gt;</code>
+         <code>&lt;management-notification-address&gt;jms.topic.notificationsTopic&lt;/management-notification-address&gt;</code>
      </pre>
      
-     <p>We will also create a queue corresponding to the example's address to hold notifications</p>
+     <p>Since we want to lookup the notifications topic using JNDI, we also declare it in  <a href="server0/hornetq-jms.xml">hornetq-jms.xml</a>
      <pre class="prettyprint">
-         <code>&lt;queues&gt;
-            &lt;queue name="jms.queue.notificationsQueue"&gt;
-               &lt;address&gt;example.notifications&lt;/address&gt;
-            &lt;/queue&gt;
-         &lt;/queues&gt;</code>
+         <code>&lt;topic name="notificationsTopic"&gt;
+            &lt;entry name="/topic/notificationsTopic"/&gt;
+         &lt;/topic&gt;</code>
      </pre>
-     
-     <p>Since we want to lookup the notifications queue using JNDI, we also declare it in  <a href="server0/hornetq-jms.xml">hornetq-jms.xml</a>
-     <pre class="prettyprint">
-         <code>&lt;queue name="notificationsQueue"&gt;
-            &lt;entry name="/queue/notificationsQueue"/&gt;
-         &lt;/queue&gt;</code>
-     </pre>
      <p>The notification queue requires permission to create/delete temporary queues and consume messages.
          This is also configured in <a href="server0/hornetq-configuration.xml">hornetq-configuration.xml</a></p>
      <pre class="prettyprint">
-         <code><!--security for notification queue-->
-         &lt;security-setting match="example.notifications"&gt;
+         <code><!--security for notification topic-->
+         &lt;security-setting match="jms.topic.notificationsTopic"&gt;
             &lt;permission type="consume" roles="guest"/&gt;
             &lt;permission type="createTempQueue" roles="guest"/&gt;
             &lt;permission type="deleteTempQueue" roles="guest"/&gt;
@@ -75,9 +66,9 @@
             MessageProducer producer = session.createProducer(queue);</code>
         </pre>
         
-        <li>We look up the JMS queue used to receive the notifications from JNDI</li>
+        <li>We look up the JMS Topic used to receive the notifications from JNDI</li>
         <pre class="prettyprint">
-            <code>Queue notificationsQueue = (Queue) initialContext.lookup("/queue/notificationsQueue");</code>
+            <code>Topic notificationsTopic = (Topic) initialContext.lookup("/topic/notificationsTopic");</code>
         </pre>
 
         <li>We create a MessageConsumer for the notification queue and set its MessageListener. When a notification is received, we will simply display all the message properties</li>

Modified: trunk/examples/jms/management-notifications/server0/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/management-notifications/server0/hornetq-configuration.xml	2010-03-29 08:39:05 UTC (rev 8993)
+++ trunk/examples/jms/management-notifications/server0/hornetq-configuration.xml	2010-03-29 09:35:53 UTC (rev 8994)
@@ -2,15 +2,8 @@
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="urn:hornetq ../../../../src/schema/hornetq-configuration.xsd">
 
-   <management-notification-address>example.notifications</management-notification-address>
+   <management-notification-address>jms.topic.notificationsTopic</management-notification-address>
 
-   <!--  create a default queue for the notification -->     
-   <queues>
-      <queue name="jms.queue.notificationsQueue">
-         <address>example.notifications</address>
-      </queue>
-   </queues>
-
    <connectors>
       <connector name="netty">
          <factory-class>org.hornetq.integration.transports.netty.NettyConnectorFactory</factory-class>
@@ -38,7 +31,7 @@
       </security-setting>
 
       <!--security for notification queue-->
-      <security-setting match="example.notifications">
+      <security-setting match="jms.topic.notificationsTopic">
          <permission type="consume" roles="guest"/>
          <permission type="createTempQueue" roles="guest"/>
          <permission type="deleteTempQueue" roles="guest"/>

Modified: trunk/examples/jms/management-notifications/server0/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/management-notifications/server0/hornetq-jms.xml	2010-03-29 08:39:05 UTC (rev 8993)
+++ trunk/examples/jms/management-notifications/server0/hornetq-jms.xml	2010-03-29 09:35:53 UTC (rev 8994)
@@ -16,8 +16,8 @@
       <entry name="/queue/exampleQueue"/>
    </queue>
 
-   <!--the notifications queue used by the example-->
-   <queue name="notificationsQueue">
-      <entry name="/queue/notificationsQueue"/>
-   </queue>
+   <!--the notifications topic used by the example-->
+   <topic name="notificationsTopic">
+      <entry name="/topic/notificationsTopic"/>
+   </topic>
 </configuration>
\ No newline at end of file

Modified: trunk/examples/jms/management-notifications/src/org/hornetq/jms/example/ManagementNotificationExample.java
===================================================================
--- trunk/examples/jms/management-notifications/src/org/hornetq/jms/example/ManagementNotificationExample.java	2010-03-29 08:39:05 UTC (rev 8993)
+++ trunk/examples/jms/management-notifications/src/org/hornetq/jms/example/ManagementNotificationExample.java	2010-03-29 09:35:53 UTC (rev 8994)
@@ -23,6 +23,7 @@
 import javax.jms.MessageProducer;
 import javax.jms.Queue;
 import javax.jms.Session;
+import javax.jms.Topic;
 import javax.naming.InitialContext;
 
 import org.hornetq.common.example.HornetQExample;
@@ -60,12 +61,12 @@
          Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
          MessageProducer producer = session.createProducer(queue);
 
-         // Step 5. Perform a lookup on the notifications queue
-         Queue notificationsQueue = (Queue)initialContext.lookup("/queue/notificationsQueue");
+         // Step 5. Perform a lookup on the notifications topic
+         Topic notificationsTopic = (Topic)initialContext.lookup("/topic/notificationsTopic");
 
          // Step 6. Create a JMS message consumer for the notification queue and set its message listener
          // It will display all the properties of the JMS Message
-         MessageConsumer notificationConsumer = session.createConsumer(notificationsQueue);
+         MessageConsumer notificationConsumer = session.createConsumer(notificationsTopic);
          notificationConsumer.setMessageListener(new MessageListener()
          {
             public void onMessage(final Message notif)



More information about the hornetq-commits mailing list