What is STOMP?
STOMP is a simple text-orientated messaging protocol. It defines an interoperable wire format so that any of the available STOMP clients can communicate with any STOMP message broker to provide easy and widespread messaging interoperability among languages and platforms (the STOMP web site has a list of STOMP client and server implementations.
What is the WebSocket API?
WebSockets are "TCP for the Web".
When Google announced the availability ofWebSocket in Google Chrome,it explained the idea behind WebSockets:
The WebSocket API enables web applications to handle bidirectional communications with server-side process in a straightforward way. Developers have been using XMLHttpRequest ("XHR") for such purposes, but XHR makes developing web applications that communicate back and forth to the server unnecessarily complex. XHR is basically asynchronous HTTP, and because you need to use a tricky technique like long-hanging GET for sending data from the server to the browser, simple tasks rapidly become complex. As opposed to XMLHttpRequest, WebSockets provide a real bidirectional communication channel in your browser. Once you get a WebSocket connection, you can send data from browser to server by calling a send() method, and receive data from server to browser by an onmessage event handler.
In addition to the new WebSocket API, there is also a new protocol (the "WebSocket Protocol") that the browser uses to communicate with servers. The protocol is not raw TCP because it needs to provide the browser's "same-origin" security model. It's also not HTTP because WebSocket traffic differers from HTTP's request-response model. WebSocket communications using the new WebSocket protocol should use less bandwidth because, unlike a series of XHRs and hanging GETs, no headers are exchanged once the single connection has been established. To use this new API and protocol and take advantage of the simpler programming model and more efficient network traffic, you do need a new server implementation to communicate with.
The API is part of HTML5 and is supported (at various degree...) by most modern Web Browsers (including Google Chrome, Firefox and Safari on Mac OS X and iOS).
Protocol Support
This library supports multiple version of STOMP protocols:
- STOMP 1.0
- STOMP 1.1 (including heart-beating)
Server Requirements
This library is not a pure STOMP client. It is aimed to run on the WebSockets protocol which is not TCP. Basically, the WebSocket protocol requires a handshake between the browser's client and the server to ensure the browser's "same-origin" security model remains in effect.
This means that this library can not connect to regular STOMP brokers since they would not understand the handshake initiated by the WebSocket which is not part of the STOMP protocol and would likely reject the connection.
There are ongoing works to add WebSocket support to STOMP broker so that they will accept STOMP connections over the WebSocket protocol.
HornetQ
HornetQ is the Open Source messaging system developed by Red Hat and JBoss.
To start HornetQ with support for STOMP Over WebSocket, download the latest version and run the following steps:
$ cd hornetq-x.y.z/examples/jms/stomp-websockets $ mvn clean install ... INFO: HQ221020: Started Netty Acceptor version 3.6.2.Final-c0d783c localhost:61614 for STOMP_WS protocol Apr 15, 2013 1:15:33 PM org.hornetq.core.server.impl.HornetQServerImpl$SharedStoreLiveActivation run INFO: HQ221007: Server is now live Apr 15, 2013 1:15:33 PM org.hornetq.core.server.impl.HornetQServerImpl start INFO: HQ221001: HornetQ Server version 2.3.0.CR2 (black'n'yellow2, 123) [c9e29e45-a5bd-11