[jboss-cvs] JBoss Messaging SVN: r6269 - in trunk/examples/jms/request-reply: src/org/jboss/jms/example and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 2 03:48:17 EDT 2009


Author: gaohoward
Date: 2009-04-02 03:48:17 -0400 (Thu, 02 Apr 2009)
New Revision: 6269

Modified:
   trunk/examples/jms/request-reply/readme.html
   trunk/examples/jms/request-reply/src/org/jboss/jms/example/RequestReplyExample.java
Log:
refined request-reply example to be more meaningful


Modified: trunk/examples/jms/request-reply/readme.html
===================================================================
--- trunk/examples/jms/request-reply/readme.html	2009-04-02 07:25:35 UTC (rev 6268)
+++ trunk/examples/jms/request-reply/readme.html	2009-04-02 07:48:17 UTC (rev 6269)
@@ -6,8 +6,10 @@
   <body>
      <h1>JMS Request-Reply Example</h1>
      <br>
-     <p>This example shows you how to send a request message and receive a reply. It first sends a request message and receives the reply message.</p>
-     <p>Request/Reply style messaging are supported through standard JMS message headers JMSReplyTo and JMSCorrelationID, please consult the JMS 1.1 specification for full details.</p>
+     <p>This example shows you how to send a request message and receive a reply. It first sends a request message with a JMSReplyTo header set to get a reply, then after 
+     receiving the request message, forges a reply message and send out to the reply queue. Then it receives the reply message.</p>
+     <p>Request/Reply style messaging is supported through standard JMS message headers JMSReplyTo and JMSCorrelationID. This is often used in request-reply style communications between applications.
+     Whenever a client sends a message that expects a response, it can use this mechanism to implement. please consult the JMS 1.1 specification for full details.</p>
      <br>
      <h2>Example step-by-step</h2>
      <p><i>To run the example, simply type <code>ant</code> from this directory</i></p>
@@ -53,6 +55,11 @@
            <code>TemporaryQueue replyQueue = session.createTemporaryQueue();</code>
         </pre>
 
+        <li>We create a JMS Message Consumer to receive request</li>
+        <pre>
+           <code>MessageConsumer messageConsumer = session.createConsumer(requestQueue);</code>
+        </pre>
+
         <li>We create a request Text Message</li>
         <pre>
            <code>TextMessage requestMsg = session.createTextMessage("A request message");</code>
@@ -73,11 +80,6 @@
            <code>producer.send(requestMsg);</code>
         </pre>
 
-        <li>We create a JMS Message Consumer to receive request</li>
-        <pre>
-           <code>MessageConsumer messageConsumer = session.createConsumer(requestQueue);</code>
-        </pre>
-
         <li>We receive the request message</li>
         <pre>
            <code>TextMessage requestMsgReceived = (TextMessage) messageConsumer.receive(5000);</code>
@@ -118,6 +120,16 @@
            <code>TextMessage replyMessageReceived = (TextMessage)replyConsumer.receive(5000);</code>
         </pre>
 
+        <li>We close the consumer and producer on the replyQueue</li>
+        <pre>
+           <code>replyConsumer.close();</code>
+           <code>replyProducer.close();</code>
+        </pre>
+
+        <li>We elete the temporary queue</li>
+        <pre>
+           <code>replyQueue.delete();</code>
+        </pre>
         
         <li>And finally, <b>always</b> remember to close your JMS connections 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>
 
@@ -139,4 +151,4 @@
 
      </ol>
   </body>
-</html>
\ No newline at end of file
+</html>

Modified: trunk/examples/jms/request-reply/src/org/jboss/jms/example/RequestReplyExample.java
===================================================================
--- trunk/examples/jms/request-reply/src/org/jboss/jms/example/RequestReplyExample.java	2009-04-02 07:25:35 UTC (rev 6268)
+++ trunk/examples/jms/request-reply/src/org/jboss/jms/example/RequestReplyExample.java	2009-04-02 07:48:17 UTC (rev 6269)
@@ -73,23 +73,23 @@
          //Step 8. Create a temporary queue used to send reply message
          TemporaryQueue replyQueue = session.createTemporaryQueue();
          
-         //Step 9. Create a request Text Message
+         //Step 9. Create a JMS Message Consumer
+         MessageConsumer messageConsumer = session.createConsumer(requestQueue);
+
+         //Step 10. Create a request Text Message
          TextMessage requestMsg = session.createTextMessage("A request message");
          
-         //Step 10. Set the ReplyTo header so that the request receiver knows where to send the reply.
+         //Step 11. Set the ReplyTo header so that the request receiver knows where to send the reply.
          requestMsg.setJMSReplyTo(replyQueue);
          
-         //Step 11. Set the CorrelationID so that it can be linked with corresponding reply message
+         //Step 12. Set the CorrelationID so that it can be linked with corresponding reply message
          requestMsg.setJMSCorrelationID("jbm-id: 0000001");
          
-         //Step 12. Sent the request message
+         //Step 13. Sent the request message
          producer.send(requestMsg);
          
          System.out.println("Request message sent.");
          
-         //Step 13. Create a JMS Message Consumer
-         MessageConsumer messageConsumer = session.createConsumer(requestQueue);
-         
          //Step 14. Receive the request message
          TextMessage requestMsgReceived = (TextMessage) messageConsumer.receive(5000);
 
@@ -121,10 +121,18 @@
          
          System.out.println("Received reply: " + replyMessageReceived.getText());
          System.out.println("CorrelatedId: " + replyMessageReceived.getJMSCorrelationID());
+
+         //Step 22 closing the consumer and producer on the replyQueue
+         replyConsumer.close();
+         replyProducer.close();
+         
+         //Step 23. Delete the temporary queue
+         replyQueue.delete();
+         
       }
       finally
       {
-         //Step 22. Be sure to close our JMS resources!
+         //Step 24. Be sure to close our JMS resources!
          if(connection != null)
          {
             connection.close();




More information about the jboss-cvs-commits mailing list