[jboss-cvs] JBoss Messaging SVN: r6412 - in trunk/examples/jms/xa-receive: src/org/jboss/jms/example and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Apr 12 12:27:30 EDT 2009


Author: gaohoward
Date: 2009-04-12 12:27:19 -0400 (Sun, 12 Apr 2009)
New Revision: 6412

Modified:
   trunk/examples/jms/xa-receive/readme.html
   trunk/examples/jms/xa-receive/src/org/jboss/jms/example/XAReceiveExample.java
Log:
document for xa-receive


Modified: trunk/examples/jms/xa-receive/readme.html
===================================================================
--- trunk/examples/jms/xa-receive/readme.html	2009-04-12 16:07:57 UTC (rev 6411)
+++ trunk/examples/jms/xa-receive/readme.html	2009-04-12 16:27:19 UTC (rev 6412)
@@ -60,11 +60,10 @@
           <code>Session normalSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code>
        </pre>
 
-        <li>We create a normal Message Consumer</li>
+        <li>We create a normal Message Producer</li>
         <pre>
            <code>
-           MessageConsumer normalConsumer = normalSession.createConsumer(queue);
-           normalConsumer.setMessageListener(new SimpleMessageListener());
+           MessageProducer normalProducer = normalSession.createProducer(queue);
            </code>
        </pre>
 
@@ -73,9 +72,9 @@
           <code>Session session = xaSession.getSession();</code>
        </pre>
 
-        <li>We create a message producer</li>
+        <li>We create a message consumer</li>
         <pre>
-          <code>MessageProducer producer = session.createProducer(queue);</code>
+          <code>MessageConsumer xaConsumer = session.createConsumer(queue); </code>
        </pre>
 
         <li>We create two Text Messages</li>
@@ -101,17 +100,22 @@
           <code>xaRes.start(xid1, XAResource.TMNOFLAGS);</code>
        </pre>
 
-        <li>We do work, sending two messages.</li>
+        <li>We send two messages.</li>
         <pre>
           <code>
-          producer.send(helloMessage);
-          producer.send(worldMessage);
+         normalProducer.send(helloMessage);
+         normalProducer.send(worldMessage);
           </code>
        </pre>
 
-        <li>We check the result, it should receive none!</li>
+        <li>We receive the messages</li>
         <pre>
-          <code>checkNoMessageReceived();</code>
+          <code>
+          TextMessage rm1 = (TextMessage)xaConsumer.receive();
+          System.out.println("Message received: " + rm1.getText());
+          TextMessage rm2 = (TextMessage)xaConsumer.receive();
+          System.out.println("Message received: " + rm2.getText());
+          </code>
        </pre>
 
         <li>We stop the work</li>
@@ -129,13 +133,8 @@
           <code>xaRes.rollback(xid1);</code>
        </pre>
 
-        <li>We check no messages should be received! </li>
+        <li>We create another transaction </li>
         <pre>
-          <code>checkNoMessageReceived();</code>
-       </pre>
-
-        <li>We create another transaction</li>
-        <pre>
           <code>Xid xid2 = new XidImpl("xa-example2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());</code>
        </pre>
 
@@ -144,12 +143,14 @@
           <code>xaRes.start(xid2, XAResource.TMNOFLAGS);</code>
        </pre>
 
-        <li>We re-send those messages</li>
+        <li>We receive those messages again</li>
         <pre>
            <code>
-           producer.send(helloMessage);
-           producer.send(worldMessage);
-           </code>
+           rm1 = (TextMessage)xaConsumer.receive();
+           System.out.println("Message received again: " + rm1.getText());
+           rm2 = (TextMessage)xaConsumer.receive();
+           System.out.println("Message received again: " + rm2.getText());
+            </code>
        </pre>
 
         <li>We stop the work</li>
@@ -162,19 +163,24 @@
           <code>xaRes.prepare(xid2);</code>
        </pre>
 
-        <li>We check that no messages should be received at this moment</li>
-        <pre>
-          <code>checkNoMessageReceived();</code>
-       </pre>
-
-        <li>We commit!</li>
-        <pre>
+       <li>We commit!</li>
+       <pre>
           <code>xaRes.commit(xid2, false);</code>
        </pre>
 
-        <li>We check that all messages are received.</li>
+        <li>We check that no more messages are received.</li>
         <pre>
-          <code>checkAllMessageReceived();</code>
+          <code>
+          TextMessage rm3 = (TextMessage)xaConsumer.receive(2000);
+          if (rm3 == null)
+          {
+             System.out.println("No message received after commit.");
+          }
+          else
+          {
+             result = false;
+          }
+          </code>
        </pre>
 
         <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>
@@ -194,4 +200,4 @@
         </pre>
      </ol>
   </body>
-</html>
\ No newline at end of file
+</html>

Modified: trunk/examples/jms/xa-receive/src/org/jboss/jms/example/XAReceiveExample.java
===================================================================
--- trunk/examples/jms/xa-receive/src/org/jboss/jms/example/XAReceiveExample.java	2009-04-12 16:07:57 UTC (rev 6411)
+++ trunk/examples/jms/xa-receive/src/org/jboss/jms/example/XAReceiveExample.java	2009-04-12 16:27:19 UTC (rev 6412)
@@ -105,11 +105,11 @@
          //Step 14. Begin the Transaction work
          xaRes.start(xid1, XAResource.TMNOFLAGS);
          
-         //Step 12. Send two messages.
+         //Step 15. Send two messages.
          normalProducer.send(helloMessage);
          normalProducer.send(worldMessage);
 
-         //Step 13. Receive the message
+         //Step 16. Receive the message
          TextMessage rm1 = (TextMessage)xaConsumer.receive();
          System.out.println("Message received: " + rm1.getText());
          TextMessage rm2 = (TextMessage)xaConsumer.receive();
@@ -124,28 +124,28 @@
          //Step 19. Roll back the transaction
          xaRes.rollback(xid1);
          
-         //Step 21. Create another transaction
+         //Step 20. Create another transaction
          Xid xid2 = new XidImpl("xa-example2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
          
-         //Step 22. Start the transaction
+         //Step 21. Start the transaction
          xaRes.start(xid2, XAResource.TMNOFLAGS);
          
-         //Step 23. receive those messages again
+         //Step 22. receive those messages again
          rm1 = (TextMessage)xaConsumer.receive();
          System.out.println("Message received again: " + rm1.getText());
          rm2 = (TextMessage)xaConsumer.receive();
          System.out.println("Message received again: " + rm2.getText());
          
-         //Step 24. Stop the work
+         //Step 23. Stop the work
          xaRes.end(xid2, XAResource.TMSUCCESS);
          
-         //Step 25. Prepare
+         //Step 24. Prepare
          xaRes.prepare(xid2);
          
-         //Step 27. Commit!
-         xaRes.commit(xid2, true);
+         //Step 25. Commit!
+         xaRes.commit(xid2, false);
          
-         //Step 28. Check no more message is received.
+         //Step 26. Check no more messages are received.
          TextMessage rm3 = (TextMessage)xaConsumer.receive(2000);
          if (rm3 == null)
          {
@@ -160,7 +160,7 @@
       }
       finally
       {
-         //Step 29. Be sure to close our JMS resources!
+         //Step 27. Be sure to close our JMS resources!
          if (initialContext != null)
          {
             initialContext.close();




More information about the jboss-cvs-commits mailing list