HTML and CSS Reference
and a body. STOMP message bodies can contain any text or binary data. Listing 5-1 shows
an example SEND frame containing a text body. This example depicts a NULL terminated
SEND frame, which sends a message to a destination named /topic/hello/world .
The black square at the end of the message represents NULL, an unprintable character.
Listing 5-1. A NULL Terminated SEND Frame
The content-length header communicates the size of the frame body. This header
is optional. Messages without content-length headers end with NULL ( 0x00 ) bytes to
mark the end of their body content. Messages terminated in that way cannot contain
NULL bytes in the middle of their payload.
■ The syntax of sToMP frames is handled by client and server software you can use
in your applications, but if you would like to develop your own implementation, you can refer
You can layer STOMP over WebSocket in the same manner as any TCP-level
protocol, or align it such that each STOMP frame occupies exactly one WebSocket frame.
Getting Started with Web Messaging
Now that we've examined messaging concepts, as well as some of the great benefits
WebSocket can bring to a messaging protocol like STOMP, let's build a working example
of a messaging application that communicates messages via a message broker to a client,
using STOMP over WebSocket.
In this example, we'll use a widely available open source message broker, Apache
ActiveMQ, which supports WebSocket. We'll step through configuring ActiveMQ to accept
WebSocket connections, allowing us to communicate using STOMP over WebSocket.
ActiveMQ also conveniently includes out-of-the-box demos, which we'll use to walk
through some of the concepts we've discussed. Then, we'll build our own STOMP/WS
application. You can learn more about ActiveMQ at http://activemq.apache.org .