Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit c050f5a36573c28f88618972f46c87ed40a97740 @jmesnil committed Jan 14, 2010
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="lib" path="lib/commons-logging-1.1.jar"/>
+ <classpathentry kind="lib" path="lib/hornetq-core.jar"/>
+ <classpathentry kind="lib" path="lib/hornetq-transports.jar"/>
+ <classpathentry kind="lib" path="lib/jboss-jms-api.jar"/>
+ <classpathentry kind="lib" path="lib/netty.jar"/>
+ <classpathentry kind="lib" path="lib/stompconnect-1.0.jar"/>
+ <classpathentry kind="lib" path="lib/hornetq-jms.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
@@ -0,0 +1,4 @@
+doc
+pkg
+.settings
+bin
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>hornetq-stomp</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,90 @@
+# Using StompConnect with HornetQ #
+
+This example shows how to setup a [HornetQ][hornetq] server with [Stomp][stomp] (in less than 30 lines of
+code) so that Stomp clients can connect to it.
+
+# Run The Example#
+
+## Prerequisites ##
+
+For simplicity, all the jars are included with the examples in the `lib/` directory.
+You can use Apache Ant to run the server.
+
+## Start the server ##
+
+The server is named [HornetQStompServer](src/org/hornetq/stomp/HornetQStompServer.java).
+
+ $ ant server
+ ...
+
+ server:
+ [java] 14 janv. 2010 10:57:30 org.hornetq.core.logging.impl.JULLogDelegate info
+ [java] INFO: live server is starting..
+ [java] 14 janv. 2010 10:57:30 org.hornetq.core.logging.impl.JULLogDelegate warn
+ [java] ATTENTION: Security risk! It has been detected that the cluster admin user and password have not been changed from the installation default. Please see the HornetQ user guide, cluster chapter, for instructions on how to do this.
+ [java] 14 janv. 2010 10:57:30 org.hornetq.core.logging.impl.JULLogDelegate info
+ [java] INFO: HornetQ Server version 2.0.0.GA (Hornet Queen, 113) started
+ [java] 14 janv. 2010 10:57:30 org.codehaus.stomp.tcp.TcpTransportServer doStart
+ [java] INFO: Listening for connections at: tcp://BlackBook.local:61613
+
+
+## Stomp Client ##
+
+We'll use telnet as our Stomp client:
+
+ $ telnet localhost 61613
+
+First, we connect to the server.
+To keep things simple, we've disable security from the server so that
+we can connect to it anonymously:
+
+ CONNECT
+ login:
+ passcode:
+
+ ^@
+
+(^@ is Ctl-@)
+The server replies that we are connected:
+
+ CONNECTED
+ session:null
+
+We send a message to the destination `/queue/a`:
+
+ SEND
+ destination:/queue/a
+
+ hello, hornetq!
+ ^@
+
+And we subscribe to this destination:
+
+ SUBSCRIBE
+ destination: /queue/a
+ ack:client
+
+ ^@
+
+As soon as we are subscribed, we will receive the message that was sent to the destination:
+
+ MESSAGE
+ message-id:ID:7b28be24-00f1-11df-b27f-001c42000009:0000000000000000
+ destination:/queue/a
+ timestamp:1263462299779
+ JMSXDeliveryCount:1
+ expires:0
+ subscription:/subscription-to//queue/a
+ priority:4
+
+ hello, hornetq!
+
+Finally, we acknowledge the message:
+
+ ACK
+ message-id: ID:7b28be24-00f1-11df-b27f-001c42000009:0000000000000000
+
+[hornetq]:http://jboss.org/hornetq/
+[stomp]: http://stomp.codehaus.org/
+
+
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- WARNING: Eclipse auto-generated file.
+ Any modifications will be overwritten.
+ To include a user specific buildfile here, simply create one in the same
+ directory with the processing instruction <?eclipse.ant.import?>
+ as the first entry and export the buildfile again. -->
+<project basedir="." default="server" name="hornetq-stomp">
+ <property environment="env"/>
+ <property name="debuglevel" value="source,lines,vars"/>
+ <property name="target" value="1.6"/>
+ <property name="source" value="1.6"/>
+ <path id="hornetq-stomp.classpath">
+ <pathelement location="bin"/>
+ <pathelement location="lib/commons-logging-1.1.jar"/>
+ <pathelement location="lib/hornetq-core.jar"/>
+ <pathelement location="lib/hornetq-transports.jar"/>
+ <pathelement location="lib/jboss-jms-api.jar"/>
+ <pathelement location="lib/netty.jar"/>
+ <pathelement location="lib/stompconnect-1.0.jar"/>
+ <pathelement location="lib/hornetq-jms.jar"/>
+ </path>
+ <target name="init">
+ <mkdir dir="bin"/>
+ <copy includeemptydirs="false" todir="bin">
+ <fileset dir="src">
+ <exclude name="**/*.launch"/>
+ <exclude name="**/*.java"/>
+ </fileset>
+ </copy>
+ </target>
+
+ <target name="clean">
+ <delete dir="bin"/>
+ </target>
+
+ <target depends="init" name="build">
+ <echo message="${ant.project.name}: ${ant.file}"/>
+ <javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
+ <src path="src"/>
+ <classpath refid="hornetq-stomp.classpath"/>
+ </javac>
+ </target>
+
+ <target name="server" depends="build">
+ <java classname="org.hornetq.stomp.HornetQStompServer" failonerror="true" fork="yes">
+ <classpath refid="hornetq-stomp.classpath"/>
+ </java>
+ </target>
+</project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,57 @@
+package org.hornetq.stomp;
+
+import javax.jms.ConnectionFactory;
+
+import org.codehaus.stomp.jms.StompConnect;
+import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.api.jms.HornetQJMSClient;
+import org.hornetq.core.config.Configuration;
+import org.hornetq.core.config.impl.ConfigurationImpl;
+import org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory;
+import org.hornetq.core.remoting.impl.invm.InVMConnectorFactory;
+import org.hornetq.core.server.HornetQServer;
+import org.hornetq.core.server.HornetQServers;
+import org.hornetq.core.server.cluster.QueueConfiguration;
+import org.hornetq.jms.server.JMSServerManager;
+import org.hornetq.jms.server.impl.JMSServerManagerImpl;
+
+/**
+ * Create HornetQ Server with a Stomp Connector.
+ */
+public class HornetQStompServer {
+
+ public static void main(String[] args) throws Exception {
+
+ // to keep things simple, we disable persistence and security
+ Configuration configuration = new ConfigurationImpl();
+ configuration.setPersistenceEnabled(false);
+ configuration.setSecurityEnabled(false);
+ // we add a In-VM acceptor to HornetQ as the server will be accessible
+ // outside using Stomp
+ configuration.getAcceptorConfigurations().add(
+ new TransportConfiguration(InVMAcceptorFactory.class.getName()));
+ // we add a Queue which will be available to Stomp under /queue/a
+ configuration.getQueueConfigurations().add(
+ new QueueConfiguration("jms.queue.a", "jms.queue.a",null, true));
+
+ // we create the HornetQ server using this config
+ HornetQServer hornetqServer = HornetQServers
+ .newHornetQServer(configuration);
+ // we also create a JMS server manager as Stomp is using the JMS API
+ JMSServerManager jmsServer = new JMSServerManagerImpl(hornetqServer);
+ // starting the JMS server will also start the underneath HornetQ server
+ jmsServer.start();
+
+ // We create directly a JMS ConnectionFactory which will be
+ // connected to the HornetQ server using In-VM connection
+ ConnectionFactory connectionFactory = HornetQJMSClient
+ .createConnectionFactory(new TransportConfiguration(
+ InVMConnectorFactory.class.getName()));
+
+ // We inject the connection factory in Stomp
+ StompConnect stompConnect = new StompConnect(connectionFactory);
+ // and start it using default Stomp config
+ stompConnect.start();
+ }
+
+}

0 comments on commit c050f5a

Please sign in to comment.