[hornetq-commits] JBoss hornetq SVN: r8999 - in trunk/examples/jms/stomp: src/org/hornetq/jms/example and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Mar 29 09:52:10 EDT 2010


Author: jmesnil
Date: 2010-03-29 09:52:09 -0400 (Mon, 29 Mar 2010)
New Revision: 8999

Modified:
   trunk/examples/jms/stomp/readme.html
   trunk/examples/jms/stomp/src/org/hornetq/jms/example/StompExample.java
Log:
fix Stomp example

* Stomp destination must correspond to HornetQ address when SENDing a message
* Stomp messages are mapped to JMS ByteMessage
* udpated readme

Modified: trunk/examples/jms/stomp/readme.html
===================================================================
--- trunk/examples/jms/stomp/readme.html	2010-03-29 13:35:27 UTC (rev 8998)
+++ trunk/examples/jms/stomp/readme.html	2010-03-29 13:52:09 UTC (rev 8999)
@@ -33,11 +33,12 @@
           sendFrame(socket, connectFrame);
         </pre>
 
-        <li>We send a SEND frame (a Stomp message) to the queue <code>/queue/exampleQueue</code> with a text body</li>
+        <li>We send a SEND frame (a Stomp message) to the destination <code>jms.queue.exampleQueue</code> 
+          (which corresponds to the HornetQ address for the JMS Queue <code>exampleQueue</code>) with a text body</li>
         <pre class="prettyprint">
           String text = "Hello, world from Stomp!";
           String message = "SEND\n" + 
-             "destination: /queue/exampleQueue\n" +
+             "destination: jms.queue.exampleQueue\n" +
              "\n" +
              text +
              Stomp.NULL;
@@ -81,11 +82,13 @@
            <code>connection.start();</code>
         </pre>
 
-        <li>We receive the message. Since the Stomp message contained a text body,
-          the corresponding JMS Message is a TextMessage</li>
+        <li>We receive the message. Stomp messages are mapped to JMS BytesMessages.</li>
         <pre class="prettyprint">
-          TextMessage messageReceived = (TextMessage)consumer.receive(5000);
-          System.out.println("Received JMS message: " + messageReceived.getText());
+          BytesMessage messageReceived = (BytesMessage)consumer.receive(5000);
+          byte[] data = new byte[1024];
+          int size = messageReceived.readBytes(data);
+          String receivedText = new String(data, 0, size, "UTF-8");
+          System.out.println("Received JMS message: " + receivedText);
         </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>

Modified: trunk/examples/jms/stomp/src/org/hornetq/jms/example/StompExample.java
===================================================================
--- trunk/examples/jms/stomp/src/org/hornetq/jms/example/StompExample.java	2010-03-29 13:35:27 UTC (rev 8998)
+++ trunk/examples/jms/stomp/src/org/hornetq/jms/example/StompExample.java	2010-03-29 13:52:09 UTC (rev 8999)
@@ -15,12 +15,12 @@
 import java.io.OutputStream;
 import java.net.Socket;
 
+import javax.jms.BytesMessage;
 import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
 import javax.jms.MessageConsumer;
 import javax.jms.Queue;
 import javax.jms.Session;
-import javax.jms.TextMessage;
 import javax.naming.InitialContext;
 
 import org.hornetq.common.example.HornetQExample;
@@ -64,7 +64,7 @@
          // queue /queue/exampleQueue with a text body
          String text = "Hello, world from Stomp!";
          String message = "SEND\n" + 
-            "destination: /queue/exampleQueue\n" +
+            "destination: jms.queue.exampleQueue\n" +
             "\n" +
             text +
             END_OF_FRAME;
@@ -98,8 +98,11 @@
          connection.start();
 
          // Step 10. Receive the message
-         TextMessage messageReceived = (TextMessage)consumer.receive(5000);
-         System.out.println("Received JMS message: " + messageReceived.getText());
+         BytesMessage messageReceived = (BytesMessage)consumer.receive(5000);
+         byte[] data = new byte[1024];
+         int size = messageReceived.readBytes(data);
+         String receivedText = new String(data, 0, size, "UTF-8");
+         System.out.println("Received JMS message: " + receivedText);
 
          return true;
       }



More information about the hornetq-commits mailing list