[jboss-cvs] JBoss Messaging SVN: r6502 - in trunk: examples/jms/common and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Apr 20 13:01:29 EDT 2009


Author: timfox
Date: 2009-04-20 13:01:29 -0400 (Mon, 20 Apr 2009)
New Revision: 6502

Modified:
   trunk/.classpath
   trunk/examples/jms/common/build.xml
   trunk/examples/jms/divert/readme.html
   trunk/examples/jms/divert/src/org/jboss/jms/example/DivertExample.java
Log:
fixed readme on divert example

Modified: trunk/.classpath
===================================================================
--- trunk/.classpath	2009-04-20 16:56:55 UTC (rev 6501)
+++ trunk/.classpath	2009-04-20 17:01:29 UTC (rev 6502)
@@ -23,6 +23,7 @@
 	<classpathentry kind="src" path="examples/jms/interceptor/src"/>
 	<classpathentry kind="src" path="examples/jms/application-layer-failover/src"/>
 	<classpathentry kind="src" path="examples/jms/automatic-failover/src"/>
+	<classpathentry kind="src" path="examples/jms/symmetric-cluster/src"/>
 	<classpathentry kind="src" path="examples/jms/browser/src"/>
 	<classpathentry kind="src" path="examples/jms/client-side-load-balancing/src"/>
 	<classpathentry kind="src" path="examples/jms/clustered-durable-subscription/src"/>

Modified: trunk/examples/jms/common/build.xml
===================================================================
--- trunk/examples/jms/common/build.xml	2009-04-20 16:56:55 UTC (rev 6501)
+++ trunk/examples/jms/common/build.xml	2009-04-20 17:01:29 UTC (rev 6502)
@@ -141,7 +141,13 @@
       <delete dir="./server1/logs" quiet="true" />
       <delete dir="./server1/data" quiet="true" />
       <delete dir="./server2/logs" quiet="true" />
-      <delete dir="./server2/data" quiet="true" />
+      <delete dir="./server2/data" quiet="true" />      
+      <delete dir="./server3/logs" quiet="true" />
+      <delete dir="./server3/data" quiet="true" />
+      <delete dir="./server4/logs" quiet="true" />
+      <delete dir="./server4/data" quiet="true" />
+      <delete dir="./server5/logs" quiet="true" />
+      <delete dir="./server5/data" quiet="true" />
    </target>
     
    <target name="all" description="Run all the JMS examples">

Modified: trunk/examples/jms/divert/readme.html
===================================================================
--- trunk/examples/jms/divert/readme.html	2009-04-20 16:56:55 UTC (rev 6501)
+++ trunk/examples/jms/divert/readme.html	2009-04-20 17:01:29 UTC (rev 6502)
@@ -2,87 +2,409 @@
   <head>
     <title>JBoss Messaging Divert Example</title>
     <link rel="stylesheet" type="text/css" href="../common/common.css">
-  </head>
   <body>
      <h1>JBoss Messaging Divert Example</h1>
      <br>
-     <p>This example shows you how to send and receive a message to a JMS Queue with JBoss Messaging.</p>
-     <p>Queues are a standard part of JMS, please consult the JMS 1.1 specification for full details.</p>
-     <p>A Queue is used to send messages point to point, from a producer to a consumer. The queue guarantees message ordering between these 2 points.</p>
-     <br>
+     <p>JBoss Messaging diverts allow messages to be transparently "diverted" from one address to another
+     with just some simple configuration defined on the server side.</p>
+     <p>Diverts can be defined to be <b>exclusive</b> or <b>non-exclusive</b>.</p>
+     <p>With an <b>exclusive</b> divert the message is intercepted and does not get sent to the queues originally
+     bound to that address - it only gets diverted.</p>
+     <p>With a <b>non-exclusive</b> divert the message continues to go to the queues bound to the address,
+     but also a <b>copy</b> of the message gets sent to the address specified in the divert. Consequently non-exclusive
+     diverts can be used to "snoop" on another address</p>
+     <p>Diverts can also be configured to have an optional filter. If specified then only matching messages
+     will be diverted.</p>
+     <p>Diverts can be configured to apply a Transformer. If specified, all diverted messages will have the
+     opportunity of being transformed by the Transformer.</p>
+     <p>Diverts are a very sophisticated concept, which when combined with bridges can be used to create
+     interesting and complex routings. The set of diverts can be thought of as a type of <i>routing table</i>
+     for messages.</p>
+     
      <h2>Example step-by-step</h2>
+     <p>In this example we will imagine a fictitious company which has two offices; one in London and another in New York.</p>
+     <p>The company accepts orders for it's products only at it's London office, and also generates price-updates
+     for it's products, also only from it's London office. However only the New York office is interested in receiving
+     price updates for New York products. Any prices for New York products need to be forwarded to the New York office.</p>
+     <p>There is an unreliable WAN linking the London and New York offices.</p>
+     <p>The company also requires a copy of any order received to be available to be inspected by management.</p>
+     <p>In order to achieve this, we will create a queue <code>orderQueue</code> on the London server in to which orders arrive.</p>
+     <p>We will create a topic, <code>spyTopic</code> on the London server, and there will be two subscribers both in London.</p>
+     <p>We will create a <i>non-exclusive</i> divert on the London server which will siphon off a copy of each order
+     received to the topic <code>spyTopic</code>.</p>
+     <p>Here's the xml config for that divert, from <code>jbm-configuration.xml</code></p>
+     <pre>
+        <code>
+     &lt;divert name="order-divert"&gt;                 
+         &lt;address&gt;jms.queue.orders&lt;/address&gt;
+         &lt;forwarding-address&gt;jms.topic.spyTopic&lt;/forwarding-address&gt;         
+         &lt;exclusive&gt;false&lt;/exclusive&gt;
+      &lt;/divert&gt;
+         </code>
+     </pre>
+     <p>For the prices we will create a topic on the London server, <code>priceUpdates</code> to which all price updates
+     are sent. We will create another topic on the New York server <code>newYorkPriceUpdates</code> to which all New York
+     price updates need to be forwarded.</p>
+     <p>Diverts can only be used to divert messages from one <b>local</b> address to another <b>local</b> address
+     so we cannot divert directly to an address on another server.</p>
+     <p>Instead we divert to a local <i>store and forward queue</i> they we define in the configuration. This is just a normal queue
+     that we use for storing messages before forwarding to another node.</p>
+     <p>Here's the configuration for it:</p>
+     <pre>
+        <code>
+     &lt;queues&gt;     
+        &lt;queue name="jms.queue.priceForwarding"&gt;
+           &lt;address&gt;jms.queue.priceForwarding&lt;/address&gt;
+        &lt;/queue&gt;
+     &lt;/queues&gt;
+         </code>
+      </pre>
+     <p>Here's the configuration for the divert:</p>
+     <pre>
+        <code>
+     &lt;divert name="prices-divert"&gt;                  
+	     &lt;address&gt;jms.topic.priceUpdates&lt;/address&gt;
+	     &lt;forwarding-address&gt;jms.queue.priceForwarding&lt;/forwarding-address&gt;    
+	     &lt;filter string="office='New York'"/&gt;
+	     &lt;transformer-class-name&gt;org.jboss.jms.example.AddForwardingTimeTransformer&lt;/transformer-class-name&gt;     
+	     &lt;exclusive&gt;true&lt;/exclusive&gt;
+	  &lt;/divert&gt;
+	     </code>
+	  </pre>
+	  <p>Note we specify a filter in the divert, so only New York prices get diverted. We also specify a Transformer class
+	  since we are going to insert a header in the message at divert time, recording the time the diversion happened.</p>
+	  <p>And finally we define a bridge that moves messages from the local queue to the address on the New York server.
+	  Bridges move messages from queues to remote addresses and are ideal to use when the target server may be stopped and
+	  started independently, and/or the network might be unreliable. Bridges guarantee once and only once delivery
+	  of messages from their source queues to their target addresses.</p>
+	  <p>Here is the bridge configuration: </p>
+	  <pre>
+	     <code>
+	  &lt;bridges&gt;
+	     &lt;bridge name="price-forward-bridge"&gt;
+	        &lt;queue-name&gt;jms.queue.priceForwarding&lt;/queue-name&gt;
+	        &lt;forwarding-address&gt;jms.topic.newYorkPriceUpdates&lt;/forwarding-address&gt;         
+	        &lt;reconnect-attempts&gt;-1&lt;/reconnect-attempts&gt;
+	        &lt;connector-ref connector-name="newyork-connector"/&gt;          
+	     &lt;/bridge&gt;
+      &lt;/bridges&gt;
+         </code> 
+     </pre>
+     
      <p><i>To run the example, simply type <code>ant</code> from this directory</i></p>
      <br>
      <ol>
-        <li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>client-jndi.properties</code> file in the directory <code>../common/config</code></li>
+        <li>Create an initial context to perform the JNDI lookup on the London server</li>
         <pre>
-           <code>InitialContext initialContext = getContext();</code>
+           <code>
+     initialContext0 = getContext(0);
+           </code>
         </pre>
 
-        <li>We look-up the JMS queue object from JNDI</li>
+        <li>Look-up the queue orderQueue on the London server - this is the queue any orders are sent to</li>
         <pre>
-           <code>Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");</code>
+           <code>
+     Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
+           </code>
         </pre>
 
-        <li>We look-up the JMS connection factory object from JNDI</li>
+        <li>Look-up the topic priceUpdates on the London server- this is the topic that any price updates are sent to</li>
         <pre>
-           <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code>
+           <code>
+     Topic priceUpdates = (Topic)initialContextLondon.lookup("/topic/priceUpdates");
+           </code>
         </pre>
 
-        <li>We create a JMS connection</li>
+        <li>Look-up the spy topic on the London server- this is what we will use to snoop on any orders</li>
         <pre>
-           <code>connection = cf.createConnection();</code>
+           <code>
+     Topic spyTopic = (Topic)initialContextLondon.lookup("/topic/spyTopic");
+           </code>
         </pre>
 
-        <li>We create a JMS session. The session is created as non transacted and will auto acknowledge messages.</li>
+        <li>Create an initial context to perform the JNDI lookup on the New York server.</li>
         <pre>
-           <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code>
+           <code>
+     initialContextNewYork = getContext(1);
+           </code>
         </pre>
 
-        <li>We create a JMS message producer on the session. This will be used to send the messages.</li>
+        <li>Look-up the topic newYorkPriceUpdates on the New York server - any price updates sent to priceUpdates on the London server will
+         be diverted to the queue priceForward on the London server, and a bridge will consume from that queue and forward
+         them to the address newYorkPriceUpdates on the New York server where they will be distributed to the topic subscribers on
+         the New York server.        
+        </li>
         <pre>
-          <code>MessageProducer messageProducer = session.createProducer(topic);</code>
+          <code>
+     Topic newYorkPriceUpdates = (Topic)initialContextNewYork.lookup("/topic/newYorkPriceUpdates");
+          </code>
        </pre>
 
-        <li>We create a JMS text message that we are going to send.</li>
+        <li>Perform a lookup on the Connection Factory on the London server</li>
         <pre>
-           <code>TextMessage message = session.createTextMessage("This is a text message");</code>
+           <code>
+    ConnectionFactory cfLondon = (ConnectionFactory)initialContextLondon.lookup("/ConnectionFactory");    
+           </code>
         </pre>
 
-        <li>We send message to the queue</li>
+        <li>Perform a lookup on the Connection Factory on the New York server.</li>
         <pre>
-           <code>messageProducer.send(message);</code>
+           <code>
+    ConnectionFactory cfNewYork = (ConnectionFactory)initialContextNewYork.lookup("/ConnectionFactory");
+           </code>
         </pre>
 
-        <li>We create a JMS Message Consumer to receive the message.</li>
+        <li>Create a JMS Connection on the London server</li>
           <pre>
-           <code>MessageConsumer messageConsumer = session.createConsumer(queue);</code>
+           <code>
+    connectionLondon = cfLondon.createConnection();
+           </code>
         </pre>
+        
+        <li>Create a JMS Connection on the New York server</li>
+          <pre>
+           <code>
+    connectionNewYork = cfNewYork.createConnection();
+           </code>
+        </pre>        
 
-        <li>We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started</li>
+        <li>Create a JMS Session on the London server.</li>
         <pre>
-           <code>connection.start();</code>
+           <code>
+    Session sessionLondon = connectionLondon.createSession(false, Session.AUTO_ACKNOWLEDGE);           
+           </code>
         </pre>
+        
+        <li>Create a JMS Session on the New York server.</li>
+        <pre>
+           <code>
+    Session sessionNewYork = connectionNewYork.createSession(false, Session.AUTO_ACKNOWLEDGE);           
+           </code>
+        </pre>        
 
-        <li>The message arrives at the consumer. In this case we use a timeout of 5000 milliseconds but we could use a blocking 'receive()'</li>
+        <li>Create a JMS MessageProducer orderProducer that sends to the queue orderQueue on the London server.</li>
         <pre>
-           <code>TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);</code>
+           <code>
+    MessageProducer orderProducer = sessionLondon.createProducer(orderQueue);
+           /code>
         </pre>
+        
+        <li>Create a JMS MessageProducer priceProducer that sends to the topic priceUpdates on the London server.</li>
+        <pre>
+           <code>
+    MessageProducer priceProducer = sessionLondon.createProducer(priceUpdates);
+           /code>
+        </pre>      
+        
+        <li>Create a JMS subscriber which subscribes to the spyTopic on the London server</li>
+        <pre>
+           <code>
+    MessageConsumer spySubscriberA = sessionLondon.createConsumer(spyTopic);    
+           </code>
+        </pre> 
+        
+        <li>Create another JMS subscriber which also subscribes to the spyTopic on the London server</li>
+        <pre>
+           <code>
+    MessageConsumer spySubscriberB = sessionLondon.createConsumer(spyTopic);
+           </code>
+        </pre>
+        
+        <li>Create a JMS MessageConsumer which consumes orders from the order queue on the London server</li>
+        <pre>
+           <code>
+    MessageConsumer orderConsumer = sessionLondon.createConsumer(orderQueue);
+           </code>
+        </pre>
+        
+        <li>Create a JMS subscriber which subscribes to the priceUpdates topic on the London server</li>
+        <pre>
+           <code>
+    MessageConsumer priceUpdatesSubscriberLondon = sessionLondon.createConsumer(priceUpdates);
+           </code>
+        </pre>   
+        
+        <li>Create a JMS subscriber which subscribes to the newYorkPriceUpdates topic on the New York server</li>
+        <pre>
+           <code>
+    MessageConsumer newYorkPriceUpdatesSubscriberA = sessionNewYork.createConsumer(newYorkPriceUpdates);
+           </code>
+        </pre>   
+        
+        <li>Create another JMS subscriber which also subscribes to the newYorkPriceUpdates topic on the New York server</li>
+        <pre>
+           <code>
+    MessageConsumer newYorkPriceUpdatesSubscriberB = sessionNewYork.createConsumer(newYorkPriceUpdates);
+           </code>
+        </pre> 
+        
+        <li>Start the connections</li>
+        <pre>
+           <code>
+    connectionLondon.start();
 
-        <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>
+    connectionNewYork.start();
+           </code>
+        </pre> 
+        
+        <li>Create an order message</li>
+        <pre>
+           <code>
+    TextMessage orderMessage = sessionLondon.createTextMessage("This is an order");
+           </code>
+        </pre> 
+        
+        <li>Send the order message to the order queue on the London server</li>
+        <pre>
+           <code>
+    orderProducer.send(orderMessage);
 
+    System.out.println("Sent message: " + orderMessage.getText());
+           </code>
+        </pre> 
+        
+        <li>The order message is consumed by the orderConsumer on the London server</li>
         <pre>
-           <code>finally
-           {
-              if (initialContext != null)
-              {
-                initialContext.close();
-              }
-              if (connection != null)
-              {
-                 connection.close();
-              }
-           }</code>
+           <code>
+    TextMessage receivedOrder = (TextMessage)orderConsumer.receive(5000);
+
+    System.out.println("Received order: " + receivedOrder.getText());
+           </code>
+        </pre> 
+        
+        <li>A copy of the order is also received by the spyTopic subscribers on the London server</li>
+        <pre>
+           <code>
+    TextMessage spiedOrder1 = (TextMessage)spySubscriberA.receive(5000);
+
+    System.out.println("Snooped on order: " + spiedOrder1.getText());
+
+    TextMessage spiedOrder2 = (TextMessage)spySubscriberB.receive(5000);
+
+    System.out.println("Snooped on order: " + spiedOrder2.getText());
+           </code>
+        </pre> 
+        
+        <li>Create and send a price update message, destined for London</li>
+        <pre>
+           <code>
+    TextMessage priceUpdateMessageLondon = sessionLondon.createTextMessage("This is a price update for London");
+                 
+    priceUpdateMessageLondon.setStringProperty("office", "London");
+         
+    priceProducer.send(priceUpdateMessageLondon);
+           </code>
+        </pre> 
+        
+        <li>The price update *should* be received by the local subscriber since we only divert messages
+        where office = New York</li>
+        <pre>
+           <code>
+    TextMessage receivedUpdate = (TextMessage)priceUpdatesSubscriberLondon.receive(2000);
+
+    System.out.println("Received price update locally: " + receivedUpdate.getText());
+           </code>
+        </pre>  
+        
+        <li>The price update *should not* be received in New York</li>
+        <pre>
+           <code>
+    TextMessage priceUpdate1 = (TextMessage)newYorkPriceUpdatesSubscriberA.receive(1000);
+
+    if (priceUpdate1 != null)
+    {
+       return false;
+    }
+   
+    System.out.println("Did not received price update in New York, look it's: " + priceUpdate1);
+   
+    TextMessage priceUpdate2 = (TextMessage)newYorkPriceUpdatesSubscriberB.receive(1000);
+
+    if (priceUpdate2 != null)
+    {
+       return false;
+    }
+   
+    System.out.println("Did not received price update in New York, look it's: " + priceUpdate2);
+           </code>
+        </pre>   
+        
+        <li>Create a price update message, destined for New York</li>
+        <pre>
+           <code>
+    TextMessage priceUpdateMessageNewYork = sessionLondon.createTextMessage("This is a price update for New York");
+         
+    priceUpdateMessageNewYork.setStringProperty("office", "New York");
+           </code>
+        </pre>   
+        
+        <li>Send the price update message to the priceUpdates topic on the London server</li>
+        <pre>
+           <code>
+   priceProducer.send(priceUpdateMessageNewYork); 
+           </code>
+        </pre>   
+        
+        <li>The price update *should not* be received by the local subscriber to the priceUpdates topic
+         since it has been *exclusively* diverted to the priceForward queue, because it has a header saying
+         it is destined for the New York office</li>
+        <pre>
+           <code>
+   Message message = priceUpdatesSubscriberLondon.receive(1000);
+
+   if (message != null)
+   {
+      return false;
+   }
+
+   System.out.println("Didn't receive local price update, look, it's: " + message); 
+           </code>
+        </pre>   
+        
+        <li>The remote subscribers on server 1 *should* receive a copy of the price update since
+        it has been diverted to a local priceForward queue which has a bridge consuming from it and which
+        forwards it to the same address on server 1.
+        We notice how the forwarded messages have had a special header added by our custom transformer that
+        we told the divert to use</li>
+        <pre>
+           <code>
+   priceUpdate1 = (TextMessage)newYorkPriceUpdatesSubscriberA.receive(5000);
+
+   System.out.println("Received forwarded price update on server 1: " + priceUpdate1.getText());
+   System.out.println("Time of forward: " + priceUpdate1.getLongProperty("time_of_forward"));
+
+   priceUpdate2 = (TextMessage)newYorkPriceUpdatesSubscriberB.receive(5000);
+
+   System.out.println("Received forwarded price update on server 2: " + priceUpdate2.getText());
+   System.out.println("Time of forward: " + priceUpdate2.getLongProperty("time_of_forward")); 
+           </code>
+        </pre>          
+        
+
+        <li>And finally, <b>always</b> remember to close your resources after use, in a <code>finally</code> block.</li>
+
+        <pre>
+           <code>
+   finally
+   {
+      if (initialContextLondon != null)
+      {
+         initialContextLondon.close();
+      }
+      if (initialContextNewYork != null)
+      {
+         initialContextNewYork.close();
+      }
+      if (connectionLondon != null)
+      {
+         connectionLondon.close();
+      }
+      if (connectionNewYork != null)
+      {
+         connectionNewYork.close();
+      }
+   }
+           </code>
         </pre>
 
 

Modified: trunk/examples/jms/divert/src/org/jboss/jms/example/DivertExample.java
===================================================================
--- trunk/examples/jms/divert/src/org/jboss/jms/example/DivertExample.java	2009-04-20 16:56:55 UTC (rev 6501)
+++ trunk/examples/jms/divert/src/org/jboss/jms/example/DivertExample.java	2009-04-20 17:01:29 UTC (rev 6502)
@@ -49,86 +49,86 @@
 
    public boolean runExample() throws Exception
    {
-      Connection connection0 = null;
+      Connection connectionLondon = null;
 
-      Connection connection1 = null;
+      Connection connectionNewYork = null;
 
-      InitialContext initialContext0 = null;
+      InitialContext initialContextLondon = null;
 
-      InitialContext initialContext1 = null;
+      InitialContext initialContextNewYork = null;
       try
       {
          // Step 1. Create an initial context to perform the JNDI lookup on the London server
-         initialContext0 = getContext(0);
+         initialContextLondon = getContext(0);
 
          // Step 2. Look-up the queue orderQueue on the London server - this is the queue any orders are sent to
-         Queue orderQueue0 = (Queue)initialContext0.lookup("/queue/orders");
+         Queue orderQueue = (Queue)initialContextLondon.lookup("/queue/orders");
 
          // Step 3. Look-up the topic priceUpdates on the London server- this is the topic that any price updates are sent to
-         Topic priceUpdates0 = (Topic)initialContext0.lookup("/topic/priceUpdates");
+         Topic priceUpdates = (Topic)initialContextLondon.lookup("/topic/priceUpdates");
 
          // Step 4. Look-up the spy topic on the London server- this is what we will use to snoop on any orders
-         Topic spyTopic0 = (Topic)initialContext0.lookup("/topic/spyTopic");
+         Topic spyTopic = (Topic)initialContextLondon.lookup("/topic/spyTopic");
 
          // Step 6. Create an initial context to perform the JNDI lookup on the New York server
-         initialContext1 = getContext(1);
+         initialContextNewYork = getContext(1);
 
          // Step 7. Look-up the topic newYorkPriceUpdates on the New York server - any price updates sent to priceUpdates on the London server will
          // be diverted to the queue priceForward on the London server, and a bridge will consume from that queue and forward
          // them to the address newYorkPriceUpdates on the New York server where they will be distributed to the topic subscribers on
          // the New York server
-         Topic newYorkPriceUpdates = (Topic)initialContext1.lookup("/topic/newYorkPriceUpdates");
+         Topic newYorkPriceUpdates = (Topic)initialContextNewYork.lookup("/topic/newYorkPriceUpdates");
 
          // Step 8. Perform a lookup on the Connection Factory on the London server
-         ConnectionFactory cf0 = (ConnectionFactory)initialContext0.lookup("/ConnectionFactory");
+         ConnectionFactory cfLondon = (ConnectionFactory)initialContextLondon.lookup("/ConnectionFactory");
 
          // Step 9. Perform a lookup on the Connection Factory on the New York server
-         ConnectionFactory cf1 = (ConnectionFactory)initialContext1.lookup("/ConnectionFactory");
+         ConnectionFactory cfNewYork = (ConnectionFactory)initialContextNewYork.lookup("/ConnectionFactory");
 
          // Step 10. Create a JMS Connection on the London server
-         connection0 = cf0.createConnection();
+         connectionLondon = cfLondon.createConnection();
 
          // Step 11. Create a JMS Connection on the New York server
-         connection1 = cf1.createConnection();
+         connectionNewYork = cfNewYork.createConnection();
 
          // Step 12. Create a JMS Session on the London server
-         Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         Session sessionLondon = connectionLondon.createSession(false, Session.AUTO_ACKNOWLEDGE);
 
          // Step 13. Create a JMS Session on the New York server
-         Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         Session sessionNewYork = connectionNewYork.createSession(false, Session.AUTO_ACKNOWLEDGE);
 
          // Step 14. Create a JMS MessageProducer orderProducer that sends to the queue orderQueue on the London server
-         MessageProducer orderProducer = session0.createProducer(orderQueue0);
+         MessageProducer orderProducer = sessionLondon.createProducer(orderQueue);
 
          // Step 15. Create a JMS MessageProducer priceProducer that sends to the topic priceUpdates on the London server
-         MessageProducer priceProducer = session0.createProducer(priceUpdates0);
+         MessageProducer priceProducer = sessionLondon.createProducer(priceUpdates);
 
          // Step 15. Create a JMS subscriber which subscribes to the spyTopic on the London server
-         MessageConsumer spySubscriberA = session0.createConsumer(spyTopic0);
+         MessageConsumer spySubscriberA = sessionLondon.createConsumer(spyTopic);
 
          // Step 16. Create another JMS subscriber which also subscribes to the spyTopic on the London server
-         MessageConsumer spySubscriberB = session0.createConsumer(spyTopic0);
+         MessageConsumer spySubscriberB = sessionLondon.createConsumer(spyTopic);
 
          // Step 17. Create a JMS MessageConsumer which consumes orders from the order queue on the London server
-         MessageConsumer orderConsumer = session0.createConsumer(orderQueue0);
+         MessageConsumer orderConsumer = sessionLondon.createConsumer(orderQueue);
 
          // Step 18. Create a JMS subscriber which subscribes to the priceUpdates topic on the London server
-         MessageConsumer priceUpdatesSubscriber0 = session0.createConsumer(priceUpdates0);
+         MessageConsumer priceUpdatesSubscriberLondon = sessionLondon.createConsumer(priceUpdates);
 
          // Step 19. Create a JMS subscriber which subscribes to the newYorkPriceUpdates topic on the New York server
-         MessageConsumer newYorkPriceUpdatesSubscriberA = session1.createConsumer(newYorkPriceUpdates);
+         MessageConsumer newYorkPriceUpdatesSubscriberA = sessionNewYork.createConsumer(newYorkPriceUpdates);
 
          // Step 20. Create another JMS subscriber which also subscribes to the newYorkPriceUpdates topic on the New York server
-         MessageConsumer newYorkPriceUpdatesSubscriberB = session1.createConsumer(newYorkPriceUpdates);
+         MessageConsumer newYorkPriceUpdatesSubscriberB = sessionNewYork.createConsumer(newYorkPriceUpdates);
 
          // Step 21. Start the connections
 
-         connection0.start();
+         connectionLondon.start();
 
-         connection1.start();
+         connectionNewYork.start();
 
          // Step 22. Create an order message
-         TextMessage orderMessage = session0.createTextMessage("This is an order");
+         TextMessage orderMessage = sessionLondon.createTextMessage("This is an order");
 
          // Step 23. Send the order message to the order queue on the London server
          orderProducer.send(orderMessage);
@@ -149,8 +149,8 @@
 
          System.out.println("Snooped on order: " + spiedOrder2.getText());
 
-         // Step 26. Create a price update message, destined for London
-         TextMessage priceUpdateMessageLondon = session0.createTextMessage("This is a price update for London");
+         // Step 26. Create and send a price update message, destined for London
+         TextMessage priceUpdateMessageLondon = sessionLondon.createTextMessage("This is a price update for London");
                  
          priceUpdateMessageLondon.setStringProperty("office", "London");
          
@@ -158,7 +158,7 @@
          
          // Step 27. The price update *should* be received by the local subscriber since we only divert messages
          // where office = New York
-         TextMessage receivedUpdate = (TextMessage)priceUpdatesSubscriber0.receive(2000);
+         TextMessage receivedUpdate = (TextMessage)priceUpdatesSubscriberLondon.receive(2000);
 
          System.out.println("Received price update locally: " + receivedUpdate.getText());
          
@@ -184,7 +184,7 @@
 
          // Step 29. Create a price update message, destined for New York
          
-         TextMessage priceUpdateMessageNewYork = session0.createTextMessage("This is a price update for New York");
+         TextMessage priceUpdateMessageNewYork = sessionLondon.createTextMessage("This is a price update for New York");
          
          priceUpdateMessageNewYork.setStringProperty("office", "New York");
       
@@ -194,7 +194,7 @@
          // Step 31. The price update *should not* be received by the local subscriber to the priceUpdates topic
          // since it has been *exclusively* diverted to the priceForward queue, because it has a header saying
          // it is destined for the New York office
-         Message message = priceUpdatesSubscriber0.receive(1000);
+         Message message = priceUpdatesSubscriberLondon.receive(1000);
 
          if (message != null)
          {
@@ -224,21 +224,21 @@
       finally
       {
          // Step 12. Be sure to close our resources!
-         if (initialContext0 != null)
+         if (initialContextLondon != null)
          {
-            initialContext0.close();
+            initialContextLondon.close();
          }
-         if (initialContext1 != null)
+         if (initialContextNewYork != null)
          {
-            initialContext1.close();
+            initialContextNewYork.close();
          }
-         if (connection0 != null)
+         if (connectionLondon != null)
          {
-            connection0.close();
+            connectionLondon.close();
          }
-         if (connection1 != null)
+         if (connectionNewYork != null)
          {
-            connection1.close();
+            connectionNewYork.close();
          }
       }
    }




More information about the jboss-cvs-commits mailing list