Author: jmesnil
Date: 2010-01-28 09:36:24 -0500 (Thu, 28 Jan 2010)
New Revision: 8856
Added:
trunk/examples/jms/stomp/
trunk/examples/jms/stomp/build.bat
trunk/examples/jms/stomp/build.sh
trunk/examples/jms/stomp/build.xml
trunk/examples/jms/stomp/readme.html
trunk/examples/jms/stomp/server0/
trunk/examples/jms/stomp/server0/client-jndi.properties
trunk/examples/jms/stomp/server0/hornetq-beans.xml
trunk/examples/jms/stomp/server0/hornetq-configuration.xml
trunk/examples/jms/stomp/server0/hornetq-jms.xml
trunk/examples/jms/stomp/server0/hornetq-users.xml
trunk/examples/jms/stomp/src/
trunk/examples/jms/stomp/src/org/
trunk/examples/jms/stomp/src/org/hornetq/
trunk/examples/jms/stomp/src/org/hornetq/jms/
trunk/examples/jms/stomp/src/org/hornetq/jms/example/
trunk/examples/jms/stomp/src/org/hornetq/jms/example/StompExample.java
Modified:
trunk/.classpath
trunk/tests/src/org/hornetq/tests/integration/stomp/StompTest.java
Log:
https://jira.jboss.org/jira/browse/HORNETQ-129: Implement STOMP v1.0
* add jms/stomp example
Modified: trunk/.classpath
===================================================================
--- trunk/.classpath 2010-01-28 13:27:55 UTC (rev 8855)
+++ trunk/.classpath 2010-01-28 14:36:24 UTC (rev 8856)
@@ -66,6 +66,7 @@
<classpathentry kind="src"
path="examples/jms/ssl-enabled/src"/>
<classpathentry kind="src"
path="examples/jms/static-selector/src"/>
<classpathentry kind="src"
path="examples/jms/static-selector-jms/src"/>
+ <classpathentry kind="src" path="examples/jms/stomp/src"/>
<classpathentry kind="src"
path="examples/jms/symmetric-cluster/src"/>
<classpathentry kind="src"
path="examples/jms/temp-queue/src"/>
<classpathentry kind="src" path="examples/jms/topic/src"/>
Added: trunk/examples/jms/stomp/build.bat
===================================================================
--- trunk/examples/jms/stomp/build.bat (rev 0)
+++ trunk/examples/jms/stomp/build.bat 2010-01-28 14:36:24 UTC (rev 8856)
@@ -0,0 +1,13 @@
+@echo off
+
+set "OVERRIDE_ANT_HOME=..\..\..\tools\ant"
+
+if exist "..\..\..\src\bin\build.bat" (
+ rem running from TRUNK
+ call ..\..\..\src\bin\build.bat %*
+) else (
+ rem running from the distro
+ call ..\..\..\bin\build.bat %*
+)
+
+set "OVERRIDE_ANT_HOME="
Added: trunk/examples/jms/stomp/build.sh
===================================================================
--- trunk/examples/jms/stomp/build.sh (rev 0)
+++ trunk/examples/jms/stomp/build.sh 2010-01-28 14:36:24 UTC (rev 8856)
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+OVERRIDE_ANT_HOME=../../../tools/ant
+export OVERRIDE_ANT_HOME
+
+if [ -f "../../../src/bin/build.sh" ]; then
+ # running from TRUNK
+ ../../../src/bin/build.sh "$@"
+else
+ # running from the distro
+ ../../../bin/build.sh "$@"
+fi
+
+
+
Property changes on: trunk/examples/jms/stomp/build.sh
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/examples/jms/stomp/build.xml
===================================================================
--- trunk/examples/jms/stomp/build.xml (rev 0)
+++ trunk/examples/jms/stomp/build.xml 2010-01-28 14:36:24 UTC (rev 8856)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE project [
+ <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
+ ]>
+<!--
+ ~ Copyright 2009 Red Hat, Inc.
+ ~ Red Hat licenses this file to you under the Apache License, version
+ ~ 2.0 (the "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
http://www.apache.org/licenses/LICENSE-2.0
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ ~ implied. See the License for the specific language governing
+ ~ permissions and limitations under the License.
+ -->
+<project default="run" name="HornetQ Stomp Example">
+
+ <import file="../../common/build.xml"/>
+
+ <target name="run">
+ <antcall target="runExample">
+ <param name="example.classname"
value="org.hornetq.jms.example.StompExample"/>
+ </antcall>
+ </target>
+
+ <target name="runRemote">
+ <antcall target="runExample">
+ <param name="example.classname"
value="org.hornetq.jms.example.StompExample"/>
+ <param name="hornetq.example.runServer"
value="false"/>
+ </antcall>
+ </target>
+
+</project>
\ No newline at end of file
Added: trunk/examples/jms/stomp/readme.html
===================================================================
--- trunk/examples/jms/stomp/readme.html (rev 0)
+++ trunk/examples/jms/stomp/readme.html 2010-01-28 14:36:24 UTC (rev 8856)
@@ -0,0 +1,111 @@
+<html>
+ <head>
+ <title>HornetQ Stomp Example</title>
+ <link rel="stylesheet" type="text/css"
href="../../common/common.css" />
+ <link rel="stylesheet" type="text/css"
href="../../common/prettify.css" />
+ <script type="text/javascript"
src="../../common/prettify.js"></script>
+ </head>
+ <body onload="prettyPrint()">
+ <h1>Stomp Example</h1>
+
+ <p>This example shows you how to configure HornetQ to send and receive Stomp
messages.</p>
+ <p>The example will start a HornetQ server configured with Stomp and
JMS.</p>
+ <p>The client will open a socket to send one Stomp message (using TCP
directly).
+ The client will then consume a message from a JMS Queue and check it is the
message sent with Stomp.</p>
+
+ <h2>Example step-by-step</h2>
+ <p><i>To run the example, simply type
<code>./build.sh</code> (or <code>build.bat</code> on windows)
from this directory</i></p>
+
+ <ol>
+ <li>We create a TCP socket to connect to the Stomp port
+ <pre class="prettyprint">
+ Socket socket = new Socket("localhost", 61613);
+ </pre>
+
+ <li>We send a CONNECT frame to connect to the server</li>
+ <pre class="prettyprint">
+ String connectFrame = "CONNECT\n" +
+ "login: guest\n" +
+ "passcode: guest\n" +
+ "request-id: 1\n" +
+ "\n" +
+ Stomp.NULL;
+ 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>
+ <pre class="prettyprint">
+ String text = "Hello, world from Stomp!";
+ String message = "SEND\n" +
+ "destination: /queue/exampleQueue\n" +
+ "\n" +
+ text +
+ Stomp.NULL;
+ sendFrame(socket, message);
+ System.out.println("Sent Stomp message: " + text);
+ </pre>
+
+ <li>We send a DISCONNECT frame to disconnect from the server</li>
+ <pre class="prettyprint">
+ String disconnectFrame = "DISCONNECT\n" +
+ "\n" +
+ Stomp.NULL;
+ sendFrame(socket, disconnectFrame);
+ </pre>
+
+ <li>We close the TCP socket</li>
+ <pre class="prettyprint">
+ socket.close();
+ </pre>
+
+ <li>We create an initial context to perform the JNDI lookup.</li>
+ <pre class="prettyprint">
+ initialContext = getContext(0);
+ </pre>
+
+ <li>We perform a lookup on the queue and the connection factory</li>
+ <pre class="prettyprint">
+ Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
+ ConnectionFactory cf =
(ConnectionFactory)initialContext.lookup("/ConnectionFactory");
+ </pre>
+
+ <li>We create a JMS Connection, Session and a MessageConsumer on the
queue</li>
+ <pre class="prettyprint">
+ connection = cf.createConnection();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer consumer = session.createConsumer(queue);
+ </pre>
+
+ <li>We start the connection</li>
+ <pre class="prettyprint">
+ <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>
+ <pre class="prettyprint">
+ TextMessage messageReceived = (TextMessage)consumer.receive(5000);
+ System.out.println("Received JMS message: " +
messageReceived.getText());
+ </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>
+
+ <pre class="prettyprint">
+ <code>finally
+ {
+ if (initialContext != null)
+ {
+ initialContext.close();
+ }
+ if (connection != null)
+ {
+ connection.close();
+ }
+ }</code>
+ </pre>
+
+
+
+ </ol>
+ </body>
+</html>
\ No newline at end of file
Added: trunk/examples/jms/stomp/server0/client-jndi.properties
===================================================================
--- trunk/examples/jms/stomp/server0/client-jndi.properties (rev
0)
+++ trunk/examples/jms/stomp/server0/client-jndi.properties 2010-01-28 14:36:24 UTC (rev
8856)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:1099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Added: trunk/examples/jms/stomp/server0/hornetq-beans.xml
===================================================================
--- trunk/examples/jms/stomp/server0/hornetq-beans.xml (rev 0)
+++ trunk/examples/jms/stomp/server0/hornetq-beans.xml 2010-01-28 14:36:24 UTC (rev 8856)
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="Naming" class="org.jnp.server.NamingBeanImpl"/>
+
+ <!-- JNDI server. Disable this if you don't want JNDI -->
+ <bean name="JNDIServer" class="org.jnp.server.Main">
+ <property name="namingInfo">
+ <inject bean="Naming"/>
+ </property>
+ <property name="port">1099</property>
+ <property name="bindAddress">localhost</property>
+ <property name="rmiPort">1098</property>
+ <property name="rmiBindAddress">localhost</property>
+ </bean>
+
+ <!-- MBean server -->
+ <bean name="MBeanServer"
class="javax.management.MBeanServer">
+ <constructor factoryClass="java.lang.management.ManagementFactory"
+ factoryMethod="getPlatformMBeanServer"/>
+ </bean>
+
+ <!-- The core configuration -->
+ <bean name="Configuration"
class="org.hornetq.core.config.impl.FileConfiguration"/>
+
+ <!-- The security manager -->
+ <bean name="HornetQSecurityManager"
class="org.hornetq.spi.core.security.HornetQSecurityManagerImpl">
+ <start ignored="true"/>
+ <stop ignored="true"/>
+ </bean>
+
+ <!-- The core server -->
+ <bean name="HornetQServer"
class="org.hornetq.core.server.impl.HornetQServerImpl">
+ <constructor>
+ <parameter>
+ <inject bean="Configuration"/>
+ </parameter>
+ <parameter>
+ <inject bean="MBeanServer"/>
+ </parameter>
+ <parameter>
+ <inject bean="HornetQSecurityManager"/>
+ </parameter>
+ </constructor>
+ <start ignored="true"/>
+ <stop ignored="true"/>
+ </bean>
+
+ <!-- The JMS server -->
+ <bean name="JMSServerManager"
class="org.hornetq.jms.server.impl.JMSServerManagerImpl">
+ <constructor>
+ <parameter>
+ <inject bean="HornetQServer"/>
+ </parameter>
+ </constructor>
+ </bean>
+
+</deployment>
Added: trunk/examples/jms/stomp/server0/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/stomp/server0/hornetq-configuration.xml
(rev 0)
+++ trunk/examples/jms/stomp/server0/hornetq-configuration.xml 2010-01-28 14:36:24 UTC
(rev 8856)
@@ -0,0 +1,42 @@
+<configuration xmlns="urn:hornetq"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq
/schema/hornetq-configuration.xsd">
+
+ <!-- Connectors -->
+
+ <connectors>
+ <connector name="netty-connector">
+
<factory-class>org.hornetq.integration.transports.netty.NettyConnectorFactory</factory-class>
+ </connector>
+ </connectors>
+
+ <!-- Acceptors -->
+ <acceptors>
+ <!-- a regular Netty acceptor used by the JMS client -->
+ <acceptor name="netty-acceptor">
+
<factory-class>org.hornetq.integration.transports.netty.NettyAcceptorFactory</factory-class>
+ </acceptor>
+ <!-- the stomp-acceptor is configured for the Stomp protocol and -->
+ <!-- will listen on port 61613 (default Stomp port) -->
+ <acceptor name="stomp-acceptor">
+
<factory-class>org.hornetq.integration.transports.netty.NettyAcceptorFactory</factory-class>
+ <param key="protocol" value="stomp" />
+ <param key="port" value="61613" />
+ </acceptor>
+ </acceptors>
+
+ <!-- Other config -->
+
+ <security-settings>
+ <!--security for example queue-->
+ <security-setting match="jms.queue.exampleQueue">
+ <permission type="createDurableQueue" roles="guest"/>
+ <permission type="deleteDurableQueue" roles="guest"/>
+ <permission type="createTempQueue" roles="guest"/>
+ <permission type="deleteTempQueue" roles="guest"/>
+ <permission type="consume" roles="guest"/>
+ <permission type="send" roles="guest"/>
+ </security-setting>
+ </security-settings>
+
+</configuration>
Added: trunk/examples/jms/stomp/server0/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/stomp/server0/hornetq-jms.xml (rev 0)
+++ trunk/examples/jms/stomp/server0/hornetq-jms.xml 2010-01-28 14:36:24 UTC (rev 8856)
@@ -0,0 +1,19 @@
+<configuration xmlns="urn:hornetq"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">
+ <!--the connection factory used by the example-->
+ <connection-factory name="ConnectionFactory">
+ <connectors>
+ <connector-ref connector-name="netty-connector"/>
+ </connectors>
+ <entries>
+ <entry name="ConnectionFactory"/>
+ </entries>
+ </connection-factory>
+
+ <!--the queue used by the example-->
+ <queue name="exampleQueue">
+ <entry name="/queue/exampleQueue"/>
+ </queue>
+
+</configuration>
Added: trunk/examples/jms/stomp/server0/hornetq-users.xml
===================================================================
--- trunk/examples/jms/stomp/server0/hornetq-users.xml (rev 0)
+++ trunk/examples/jms/stomp/server0/hornetq-users.xml 2010-01-28 14:36:24 UTC (rev 8856)
@@ -0,0 +1,7 @@
+<configuration xmlns="urn:hornetq"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-users.xsd">
+ <!-- the default user. this is used where username is null-->
+ <defaultuser name="guest" password="guest">
+ <role name="guest"/>
+ </defaultuser>
+</configuration>
\ No newline at end of file
Added: trunk/examples/jms/stomp/src/org/hornetq/jms/example/StompExample.java
===================================================================
--- trunk/examples/jms/stomp/src/org/hornetq/jms/example/StompExample.java
(rev 0)
+++ trunk/examples/jms/stomp/src/org/hornetq/jms/example/StompExample.java 2010-01-28
14:36:24 UTC (rev 8856)
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+package org.hornetq.jms.example;
+
+import java.io.OutputStream;
+import java.net.Socket;
+
+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;
+
+/**
+ * An example where a client will send a Stomp message on a TCP socket
+ * and consume it from a JMS MessageConsumer.
+ *
+ * @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a>
+ */
+public class StompExample extends HornetQExample
+{
+ private static final String END_OF_FRAME = "\u0000";
+
+ public static void main(final String[] args)
+ {
+ new StompExample().run(args);
+ }
+
+ @Override
+ public boolean runExample() throws Exception
+ {
+ Connection connection = null;
+ InitialContext initialContext = null;
+
+ try
+ {
+ // Step 1. Create a TCP socket to connect to the Stomp port
+ Socket socket = new Socket("localhost", 61613);
+
+ // Step 2. Send a CONNECT frame to connect to the server
+ String connectFrame = "CONNECT\n" +
+ "login: guest\n" +
+ "passcode: guest\n" +
+ "request-id: 1\n" +
+ "\n" +
+ END_OF_FRAME;
+ sendFrame(socket, connectFrame);
+
+ // Step 3. Send a SEND frame (a Stomp message) to the
+ // queue /queue/exampleQueue with a text body
+ String text = "Hello, world from Stomp!";
+ String message = "SEND\n" +
+ "destination: /queue/exampleQueue\n" +
+ "\n" +
+ text +
+ END_OF_FRAME;
+ sendFrame(socket, message);
+ System.out.println("Sent Stomp message: " + text);
+
+ // Step 4. Send a DISCONNECT frame to disconnect from the server
+ String disconnectFrame = "DISCONNECT\n" +
+ "\n" +
+ END_OF_FRAME;
+ sendFrame(socket, disconnectFrame);
+
+ // Step 5. Slose the TCP socket
+ socket.close();
+
+ // We will now consume from JMS the message sent with Stomp.
+
+ // Step 6. Create an initial context to perform the JNDI lookup.
+ initialContext = getContext(0);
+
+ // Step 7. Perform a lookup on the queue and the connection factory
+ Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
+ ConnectionFactory cf =
(ConnectionFactory)initialContext.lookup("/ConnectionFactory");
+
+ // Step 8.Create a JMS Connection, Session and a MessageConsumer on the queue
+ connection = cf.createConnection();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer consumer = session.createConsumer(queue);
+
+ // Step 9. Start the Connection
+ connection.start();
+
+ // Step 10. Receive the message
+ TextMessage messageReceived = (TextMessage)consumer.receive(5000);
+ System.out.println("Received JMS message: " +
messageReceived.getText());
+
+ return true;
+ }
+ finally
+ {
+ // Step 11. Be sure to close our JMS resources!
+ if (initialContext != null)
+ {
+ initialContext.close();
+ }
+ if (connection != null)
+ {
+ connection.close();
+ }
+ }
+ }
+
+ private static void sendFrame(Socket socket, String data) throws Exception
+ {
+ byte[] bytes = data.getBytes("UTF-8");
+ OutputStream outputStream = socket.getOutputStream();
+ for (int i = 0; i < bytes.length; i++)
+ {
+ outputStream.write(bytes[i]);
+ }
+ outputStream.flush();
+ }
+
+}
Modified: trunk/tests/src/org/hornetq/tests/integration/stomp/StompTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/stomp/StompTest.java 2010-01-28 13:27:55
UTC (rev 8855)
+++ trunk/tests/src/org/hornetq/tests/integration/stomp/StompTest.java 2010-01-28 14:36:24
UTC (rev 8856)
@@ -705,6 +705,7 @@
"\n\n" +
Stomp.NULL;
sendFrame(frame);
+ waitForFrameToTakeEffect();
reconnect();
}
else {
@@ -738,7 +739,8 @@
"\n\n" +
Stomp.NULL;
sendFrame(frame);
-
+ waitForFrameToTakeEffect();
+
// now lets make sure we don't see the message again
reconnect();