Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…b Sockets

* add stomp_ws protocol to support sending/receiving Stomp messages over HTML5 Web Sockets
* add stomp-websockets example
* documentation
  • Loading branch information
jmesnil committed Apr 28, 2010
1 parent 394de25 commit 204d315
Show file tree
Hide file tree
Showing 26 changed files with 1,151 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .classpath
Expand Up @@ -67,6 +67,7 @@
<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/stomp-websockets/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"/>
Expand Down Expand Up @@ -101,7 +102,7 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="tests/tmpfiles"/>
<classpathentry kind="lib" path="thirdparty/net/java/dev/javacc/lib/javacc.jar"/>
<classpathentry kind="lib" path="thirdparty/org/jboss/netty/lib/netty.jar"/>
<classpathentry kind="lib" path="thirdparty/org/jboss/netty/lib/netty.jar" sourcepath="/Users/jmesnil/Downloads/netty-3.2.0.BETA1-sources.jar"/>
<classpathentry kind="lib" path="thirdparty/log4j/lib/log4j.jar"/>
<classpathentry kind="lib" path="thirdparty/org/jboss/naming/lib/jnpserver.jar"/>
<classpathentry kind="lib" path="thirdparty/org/jboss/security/lib/jbosssx.jar"/>
Expand Down
6 changes: 6 additions & 0 deletions docs/user-manual/en/examples.xml
Expand Up @@ -420,6 +420,12 @@
<para>The <literal>stomp</literal> example shows you how to configure a
HornetQ server to send and receive Stomp messages.</para>
</section>
<section>
<title>Stomp Over Web Sockets</title>
<para>The <literal>stomp-websockets</literal> example shows you how to configure a
HornetQ server to send and receive Stomp messages directly from Web browsers (provided
they support Web Sockets).</para>
</section>
<section>
<title>Symmetric Cluster</title>
<para>The <literal>symmetric-cluster</literal> example demonstrates a symmetric cluster
Expand Down
32 changes: 28 additions & 4 deletions docs/user-manual/en/interoperability.xml
Expand Up @@ -79,10 +79,10 @@ hello queue orders
<para>send or subscribe to a JMS <emphasis>Topic</emphasis> by prepending the topic name by <literal>jms.topic.</literal>.</para>
<para>For example to subscribe to the <literal>stocks</literal> JMS Topic, the Stomp client must send the frame:</para>
<programlisting>
SUBSCRIBE
destination:jms.topic.stocks
^@
SUBSCRIBE
destination:jms.topic.stocks

^@
</programlisting>
</listitem>
</itemizedlist>
Expand All @@ -108,6 +108,30 @@ producer.send(message);
</programlisting>
</section>
</section>

<section id="stomp.websockets">
<title>Stomp Over Web Sockets</title>
<para>HornetQ also support Stomp over <ulink url="http://dev.w3.org/html5/websockets/">Web Sockets</ulink>. Modern web browser which support Web Sockets can send and receive
Stomp messages from HornetQ.</para>
<para>To enable Stomp over Web Sockets, you must configure a <literal>NettyAcceptor</literal> with a <literal>protocol</literal>
parameter set to <literal>stomp_ws</literal>:</para>
<programlisting>
&lt;acceptor name="stomp-ws-acceptor">
&lt;factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory&lt;/factory-class>
&lt;param key="protocol" value="stomp_ws"/>
&lt;param key="port" value="61614"/>
&lt;/acceptor>
</programlisting>
<para>With this configuration, HornetQ will accept Stomp connections over Web Sockets on
the port <literal>61614</literal> with the URL path <literal>/stomp</literal>.
Web browser can then connect to <literal>ws://&lt;server&gt;:61614/stomp</literal> usin a Web Socket to send and receive Stomp
messages.</para>
<para>A companion JavaScript library to ease client-side development is available from
<ulink url="http://github.com/jmesnil/stomp-websocket">GitHub</ulink> (please see
its <ulink url="http://jmesnil.net/stomp-websocket/doc/">documentation</ulink> for a complete description).</para>
<para>The <literal>stomp-websockets</literal> example shows how to configure HornetQ server to have web browsers and Java
applications exchanges messages on a JMS topic.</para>
</section>

<section id="stompconnect">
<title>StompConnect</title>
Expand Down
13 changes: 13 additions & 0 deletions examples/jms/stomp-websockets/build.bat
@@ -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="
15 changes: 15 additions & 0 deletions examples/jms/stomp-websockets/build.sh
@@ -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



28 changes: 28 additions & 0 deletions examples/jms/stomp-websockets/build.xml
@@ -0,0 +1,28 @@
<?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="runRemote" name="HornetQ Stomp Over WebSockets Example">

<import file="../../common/build.xml"/>

<target name="runRemote">
<antcall target="runExample">
<param name="example.classname" value="org.hornetq.jms.example.StompWebSocketExample"/>
<param name="hornetq.example.runServer" value="false"/>
</antcall>
</target>

</project>
99 changes: 99 additions & 0 deletions examples/jms/stomp-websockets/chat/chat.css
@@ -0,0 +1,99 @@
* {
margin: 0;
padding: 0;
}

body {
font-family: 'Helvetica Neue', Helvetica, Verdana, Arial, sans-serif;
padding: 10px;
}

#disconnect {
display: none;
}
#subscribe {
display: none;
}

#debug {
background-color: #F0F0F0;
font-size: 12px;
height: 75%;
overflow: auto;
padding: 10px;
position: absolute;
right: 10px;
top: 10px;
width: 250px;
z-index: 100;
}

#send_form {
bottom: 5px;
position: absolute;
width: 99%;
}

#send_form #send_form_input {
border: 1px solid #CCC;
font-size: 16px;
height: 20px;
padding: 5px;
width: 98%;
}

#send_form input[disabled] {
background-color: #EEE;
}

#messages {
bottom: 25px;
left: 0;
overflow: auto;
padding: 5px;
right: 0;
top: 2em;
z-index: -1;
}

.message {
width: 95%;
}

.timestamp {
font-size: 12px;
}

.me, .nick {
float: left;
width: 100px;
}

.me {
color: #F99;
}

.nick {
color: #99F;
}

.status {
background-color: #DDD;
}

form dt {
clear:both;
width:19%;
float:left;
text-align:right;
}

form dd {
float:left;
width:80%;
margin:0 0 0.5em 0.25em;
}

input {
width: 320px;
}
51 changes: 51 additions & 0 deletions examples/jms/stomp-websockets/chat/chat.js
@@ -0,0 +1,51 @@
$(document).ready(function(){

var client, destination;

$('#connect_form').submit(function() {
var url = $("#connect_url").val();
var login = $("#connect_login").val();
var passcode = $("#connect_passcode").val();
destination = $("#destination").val();

client = Stomp.client(url);

// this allows to display debug logs directly on the web page
client.debug = function(str) {
$("#debug").append(str + "\n");
};
// the client is notified when it is connected to the server.
var onconnect = function(frame) {
debug("connected to Stomp");
$('#connect').fadeOut({ duration: 'fast' });
$('#disconnect').fadeIn();
$('#send_form_input').removeAttr('disabled');

client.subscribe(destination, function(message) {
$("#messages").append("<p>" + message.body + "</p>\n");
});
};
client.connect(login, passcode, onconnect);

return false;
});

$('#disconnect_form').submit(function() {
client.disconnect(function() {
$('#disconnect').fadeOut({ duration: 'fast' });
$('#connect').fadeIn();
$('#send_form_input').addAttr('disabled');
});
return false;
});

$('#send_form').submit(function() {
var text = $('#send_form_input').val();
if (text) {
client.send(destination, {foo: 1}, text);
$('#send_form_input').val("");
}
return false;
});

});
54 changes: 54 additions & 0 deletions examples/jms/stomp-websockets/chat/index.html
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<head>
<title>Chat Example Using Stomp Over Web Sockets</title>
<link rel="stylesheet" href="chat.css" />
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'></script>
<script src='stomp.js'></script>
<script src='chat.js'></script>
<script>
$(document).ready(function() {
var supported = ("WebSocket" in window);
if(!supported) {
var msg = "Your browser does not support Web Sockets. This example will not work properly.<br>";
msg += "Please use a Web Browser with Web Sockets support (WebKit or Google Chrome).";
$("#connect").html(msg);
}
});
</script>
</head>
<body>

<div id='connect'>
<form id='connect_form'>
<dl>
<dt><label for=connect_url>Server URL</label></dt>
<dd><input name=url id='connect_url' value='ws://localhost:61614/stomp'></dd>
<dt><label for=connect_login>Login</label></dt>
<dd><input id='connect_login' placeholder="User Login" value="guest"></dd>
<dt><label for=connect_passcode>Password</label></dt>
<dd><input id='connect_passcode' type=password placeholder="User Password" value="guest"></dd>
<dt><label for=destination>Destination</label></dt>
<dd><input id='destination' placeholder="Destination" value="jms.topic.chat"></dd>
<dt>&nbsp;</dt>
<dd><input type=submit id='connect_submit' value="Connect"></dd>
</dl>
</form>

<p>Use the form above to connect to the Stomp server and subscribe to the destination.</p>
<p>Once connected, you can send messages to the destination with the text field at the bottom of this page</p>
</div>
<div id="disconnect">
<form id='disconnect_form'>
<input type=submit id='disconnect_submit' value="Disconnect">
</form>
</div>
<pre id="debug"></pre>
<div id="messages">
</div>
<form id='send_form'>
<input id='send_form_input' placeholder="Type your message here" disabled />
</form>
</body>
</html>

0 comments on commit 204d315

Please sign in to comment.