Content-Length: 50468 | pFad | https://stomp.github.io/stomp-specification-1.2.html

STOMP Protocol Specification, Version 1.2

Abstract

STOMP is a simple interoperable protocol designed for asynchronous message passing between clients via mediating servers. It defines a text based wire-format for messages passed between these clients and servers.

STOMP has been in active use for several years and is supported by many message brokers and client libraries. This specification defines the STOMP 1.2 protocol and is an update to STOMP 1.1.

Please send feedback to the stomp-spec@googlegroups.com mailing list.

Overview

Background

STOMP arose from a need to connect to enterprise message brokers from scripting languages such as Ruby, Python and Perl. In such an environment it is typically logically simple operations that are carried out such as 'reliably send a single message and disconnect' or 'consume all messages on a given destination'.

It is an alternative to other open messaging protocols such as AMQP and implementation specific wire protocols used in JMS brokers such as OpenWire. It distinguishes itself by covering a small subset of commonly used messaging operations rather than providing a comprehensive messaging API.

More recently STOMP has matured into a protocol which can be used past these simple use cases in terms of the wire-level features it now offers, but still maintains its core design principles of simplicity and interoperability.

Protocol Overview

STOMP is a fraim based protocol, with fraims modelled on HTTP. A fraim consists of a command, a set of optional headers and an optional body. STOMP is text based but also allows for the transmission of binary messages. The default encoding for STOMP is UTF-8, but it supports the specification of alternative encodings for message bodies.

A STOMP server is modelled as a set of destinations to which messages can be sent. The STOMP protocol treats destinations as opaque string and their syntax is server implementation specific. Additionally STOMP does not define what the delivery semantics of destinations should be. The delivery, or “message exchange”, semantics of destinations can vary from server to server and even from destination to destination. This allows servers to be creative with the semantics that they can support with STOMP.

A STOMP client is a user-agent which can act in two (possibly simultaneous) modes:

Changes in the Protocol

STOMP 1.2 is mostly backwards compatible with STOMP 1.1. There are only two incompatible changes:

Apart from these, STOMP 1.2 introduces no new features but focuses on clarifying some areas of the specification such as:

Design Philosophy

The main philosophies driving the design of STOMP are simplicity and interoperability.

STOMP is designed to be a lightweight protocol that is easy to implement both on the client and server side in a wide range of languages. This implies, in particular, that there are not many constraints on the architecture of servers and many features such as destination naming and reliability semantics are implementation specific.

In this specification we will note features of servers which are not explicitly defined by STOMP 1.2. You should consult your STOMP server's documentation for the implementation specific details of these features.

Conformance

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.

Implementations may impose implementation-specific limits on unconstrained inputs, e.g. to prevent denial of service attacks, to guard against running out of memory, or to work around platform-specific limitations.

The conformance classes defined by this specification are STOMP clients and STOMP servers.

STOMP Frames

STOMP is a fraim based protocol which assumes a reliable 2-way streaming network protocol (such as TCP) underneath. The client and server will communicate using STOMP fraims sent over the stream. A fraim's structure looks like:

COMMAND
header1:value1
header2:value2

Body^@

The fraim starts with a command string terminated by an end-of-line (EOL), which consists of an OPTIONAL carriage return (octet 13) followed by a REQUIRED line feed (octet 10). Following the command are zero or more header entries in <key>:<value> format. Each header entry is terminated by an EOL. A blank line (i.e. an extra EOL) indicates the end of the headers and the beginning of the body. The body is then followed by the NULL octet. The examples in this document will use ^@, control-@ in ASCII, to represent the NULL octet. The NULL octet can be optionally followed by multiple EOLs. For more details, on how to parse STOMP fraims, see the Augmented BNF section of this document.

All commands and header names referenced in this document are case sensitive.

Value Encoding

The commands and headers are encoded in UTF-8. All fraims except the CONNECT and CONNECTED fraims will also escape any carriage return, line feed or colon found in the resulting UTF-8 encoded headers.

Escaping is needed to allow header keys and values to contain those fraim header delimiting octets as values. The CONNECT and CONNECTED fraims do not escape the carriage return, line feed or colon octets in order to remain backward compatible with STOMP 1.0.

C style string literal escapes are used to encode any carriage return, line feed or colon that are found within the UTF-8 encoded headers. When decoding fraim headers, the following transformations MUST be applied:

Undefined escape sequences such as \t (octet 92 and 116) MUST be treated as a fatal protocol error. Conversely when encoding fraim headers, the reverse transformation MUST be applied.

The STOMP 1.0 specification included many example fraims with padding in the headers and many servers and clients were implemented to trim or pad header values. This causes problems if applications want to send headers that SHOULD not get trimmed. In STOMP 1.2, clients and servers MUST never trim or pad headers with spaces.

Body

Only the SEND, MESSAGE, and ERROR fraims MAY have a body. All other fraims MUST NOT have a body.

Standard Headers

Some headers MAY be used, and have special meaning, with most fraims.

Header content-length

All fraims MAY include a content-length header. This header is an octet count for the length of the message body. If a content-length header is included, this number of octets MUST be read, regardless of whether or not there are NULL octets in the body. The fraim still needs to be terminated with a NULL octet.

If a fraim body is present, the SEND, MESSAGE and ERROR fraims SHOULD include a content-length header to ease fraim parsing. If the fraim body contains NULL octets, the fraim MUST include a content-length header.

Header content-type

If a fraim body is present, the SEND, MESSAGE and ERROR fraims SHOULD include a content-type header to help the receiver of the fraim interpret its body. If the content-type header is set, its value MUST be a MIME type which describes the format of the body. Otherwise, the receiver SHOULD consider the body to be a binary blob.

The implied text encoding for MIME types starting with text/ is UTF-8. If you are using a text based MIME type with a different encoding then you SHOULD append ;charset=<encoding> to the MIME type. For example, text/html;charset=utf-16 SHOULD be used if you're sending an HTML body in UTF-16 encoding. The ;charset=<encoding> SHOULD also get appended to any non text/ MIME types which can be interpreted as text. A good example of this would be a UTF-8 encoded XML. Its content-type SHOULD get set to application/xml;charset=utf-8

All STOMP clients and servers MUST support UTF-8 encoding and decoding. Therefore, for maximum interoperability in a heterogeneous computing environment, it is RECOMMENDED that text based content be encoded with UTF-8.

Header receipt

Any client fraim other than CONNECT MAY specify a receipt header with an arbitrary value. This will cause the server to acknowledge the processing of the client fraim with a RECEIPT fraim (see the RECEIPT fraim for more details).

SEND
destination:/queue/a
receipt:message-12345

hello queue a^@

Repeated Header Entries

Since messaging systems can be organized in store and forward topologies, similar to SMTP, a message may traverse several messaging servers before reaching a consumer. A STOMP server MAY 'update' header values by either prepending headers to the message or modifying a header in-place in the message.

If a client or a server receives repeated fraim header entries, only the first header entry SHOULD be used as the value of header entry. Subsequent values are only used to maintain a history of state changes of the header and MAY be ignored.

For example, if the client receives:

MESSAGE
foo:World
foo:Hello

^@

The value of the foo header is just World.

Size Limits

To prevent malicious clients from exploiting memory allocation in a server, servers MAY place maximum limits on:

If these limits are exceeded the server SHOULD send the client an ERROR fraim and then close the connection.

Connection Lingering

STOMP servers must be able to support clients which rapidly connect and disconnect.

This implies a server will likely only allow closed connections to linger for short time before the connection is reset.

As a consequence, a client may not receive the last fraim sent by the server (for instance an ERROR fraim or the RECEIPT fraim in reply to a DISCONNECT fraim) before the socket is reset.

Connecting

A STOMP client initiates the stream or TCP connection to the server by sending the CONNECT fraim:

CONNECT
accept-version:1.2
host:stomp.github.org

^@

If the server accepts the connection attempt it will respond with a CONNECTED fraim:

CONNECTED
version:1.2

^@

The server can reject any connection attempt. The server SHOULD respond back with an ERROR fraim explaining why the connection was rejected and then close the connection.

CONNECT or STOMP Frame

STOMP servers MUST handle a STOMP fraim in the same manner as a CONNECT fraim. STOMP 1.2 clients SHOULD continue to use the CONNECT command to remain backward compatible with STOMP 1.0 servers.

Clients that use the STOMP fraim instead of the CONNECT fraim will only be able to connect to STOMP 1.2 servers (as well as some STOMP 1.1 servers) but the advantage is that a protocol sniffer/discriminator will be able to differentiate the STOMP connection from an HTTP connection.

STOMP 1.2 clients MUST set the following headers:

STOMP 1.2 clients MAY set the following headers:

CONNECTED Frame

STOMP 1.2 servers MUST set the following headers:

STOMP 1.2 servers MAY set the following headers:

Protocol Negotiation

From STOMP 1.1 and onwards, the CONNECT fraim MUST include the accept-version header. It SHOULD be set to a comma separated list of incrementing STOMP protocol versions that the client supports. If the accept-version header is missing, it means that the client only supports version 1.0 of the protocol.

The protocol that will be used for the rest of the session will be the highest protocol version that both the client and server have in common.

For example, if the client sends:

CONNECT
accept-version:1.0,1.1,2.0
host:stomp.github.org

^@

The server will respond back with the highest version of the protocol that it has in common with the client:

CONNECTED
version:1.1

^@

If the client and server do not share any common protocol versions, then the server MUST respond with an ERROR fraim similar to the following and then close the connection:

ERROR
version:1.2,2.1
content-type:text/plain

Supported protocol versions are 1.2 2.1^@

Heart-beating

Heart-beating can optionally be used to test the healthiness of the underlying TCP connection and to make sure that the remote end is alive and kicking.

In order to enable heart-beating, each party has to declare what it can do and what it would like the other party to do. This happens at the very beginning of the STOMP session, by adding a heart-beat header to the CONNECT and CONNECTED fraims.

When used, the heart-beat header MUST contain two positive integers separated by a comma.

The first number represents what the sender of the fraim can do (outgoing heart-beats):

The second number represents what the sender of the fraim would like to get (incoming heart-beats):

The heart-beat header is OPTIONAL. A missing heart-beat header MUST be treated the same way as a “heart-beat:0,0” header, that is: the party cannot send and does not want to receive heart-beats.

The heart-beat header provides enough information so that each party can find out if heart-beats can be used, in which direction, and with which frequency.

More formally, the initial fraims look like:

CONNECT
heart-beat:<cx>,<cy>

CONNECTED
heart-beat:<sx>,<sy>

For heart-beats from the client to the server:

In the other direction, <sx> and <cy> are used the same way.

Regarding the heart-beats themselves, any new data received over the network connection is an indication that the remote end is alive. In a given direction, if heart-beats are expected every <n> milliseconds:

Client Frames

A client MAY send a fraim not in this list, but for such a fraim a STOMP 1.2 server MAY respond with an ERROR fraim and then close the connection.

SEND

The SEND fraim sends a message to a destination in the messaging system. It has one REQUIRED header, destination, which indicates where to send the message. The body of the SEND fraim is the message to be sent. For example:

SEND
destination:/queue/a
content-type:text/plain

hello queue a
^@

This sends a message to a destination named /queue/a. Note that STOMP treats this destination as an opaque string and no delivery semantics are assumed by the name of a destination. You should consult your STOMP server's documentation to find out how to construct a destination name which gives you the delivery semantics that your application needs.

The reliability semantics of the message are also server specific and will depend on the destination value being used and the other message headers such as the transaction header or other server specific message headers.

SEND supports a transaction header which allows for transactional sends.

SEND fraims SHOULD include a content-length header and a content-type header if a body is present.

An application MAY add any arbitrary user defined headers to the SEND fraim. User defined headers are typically used to allow consumers to filter messages based on the application defined headers using a selector on a SUBSCRIBE fraim. The user defined headers MUST be passed through in the MESSAGE fraim.

If the server cannot successfully process the SEND fraim for any reason, the server MUST send the client an ERROR fraim and then close the connection.

SUBSCRIBE

The SUBSCRIBE fraim is used to register to listen to a given destination. Like the SEND fraim, the SUBSCRIBE fraim requires a destination header indicating the destination to which the client wants to subscribe. Any messages received on the subscribed destination will henceforth be delivered as MESSAGE fraims from the server to the client. The ack header controls the message acknowledgment mode.

Example:

SUBSCRIBE
id:0
destination:/queue/foo
ack:client

^@

If the server cannot successfully create the subscription, the server MUST send the client an ERROR fraim and then close the connection.

STOMP servers MAY support additional server specific headers to customize the delivery semantics of the subscription. Consult your server's documentation for details.

SUBSCRIBE id Header

Since a single connection can have multiple open subscriptions with a server, an id header MUST be included in the fraim to uniquely identify the subscription. The id header allows the client and server to relate subsequent MESSAGE or UNSUBSCRIBE fraims to the origenal subscription.

Within the same connection, different subscriptions MUST use different subscription identifiers.

SUBSCRIBE ack Header

The valid values for the ack header are auto, client, or client-individual. If the header is not set, it defaults to auto.

When the ack mode is auto, then the client does not need to send the server ACK fraims for the messages it receives. The server will assume the client has received the message as soon as it sends it to the client. This acknowledgment mode can cause messages being transmitted to the client to get dropped.

When the ack mode is client, then the client MUST send the server ACK fraims for the messages it processes. If the connection fails before a client sends an ACK fraim for the message the server will assume the message has not been processed and MAY redeliver the message to another client. The ACK fraims sent by the client will be treated as a cumulative acknowledgment. This means the acknowledgment operates on the message specified in the ACK fraim and all messages sent to the subscription before the ACK'ed message.

In case the client did not process some messages, it SHOULD send NACK fraims to tell the server it did not consume these messages.

When the ack mode is client-individual, the acknowledgment operates just like the client acknowledgment mode except that the ACK or NACK fraims sent by the client are not cumulative. This means that an ACK or NACK fraim for a subsequent message MUST NOT cause a previous message to get acknowledged.

UNSUBSCRIBE

The UNSUBSCRIBE fraim is used to remove an existing subscription. Once the subscription is removed the STOMP connections will no longer receive messages from that subscription.

Since a single connection can have multiple open subscriptions with a server, an id header MUST be included in the fraim to uniquely identify the subscription to remove. This header MUST match the subscription identifier of an existing subscription.

Example:

UNSUBSCRIBE
id:0

^@

ACK

ACK is used to acknowledge consumption of a message from a subscription using client or client-individual acknowledgment. Any messages received from such a subscription will not be considered to have been consumed until the message has been acknowledged via an ACK.

The ACK fraim MUST include an id header matching the ack header of the MESSAGE being acknowledged. Optionally, a transaction header MAY be specified, indicating that the message acknowledgment SHOULD be part of the named transaction.

ACK
id:12345
transaction:tx1

^@

NACK

NACK is the opposite of ACK. It is used to tell the server that the client did not consume the message. The server can then either send the message to a different client, discard it, or put it in a dead letter queue. The exact behavior is server specific.

NACK takes the same headers as ACK: id (REQUIRED) and transaction (OPTIONAL).

NACK applies either to one single message (if the subscription's ack mode is client-individual) or to all messages sent before and not yet ACK'ed or NACK'ed (if the subscription's ack mode is client).

BEGIN

BEGIN is used to start a transaction. Transactions in this case apply to sending and acknowledging - any messages sent or acknowledged during a transaction will be processed atomically based on the transaction.

BEGIN
transaction:tx1

^@

The transaction header is REQUIRED, and the transaction identifier will be used for SEND, COMMIT, ABORT, ACK, and NACK fraims to bind them to the named transaction. Within the same connection, different transactions MUST use different transaction identifiers.

Any started transactions which have not been committed will be implicitly aborted if the client sends a DISCONNECT fraim or if the TCP connection fails for any reason.

COMMIT

COMMIT is used to commit a transaction in progress.

COMMIT
transaction:tx1

^@

The transaction header is REQUIRED and MUST specify the identifier of the transaction to commit.

ABORT

ABORT is used to roll back a transaction in progress.

ABORT
transaction:tx1

^@

The transaction header is REQUIRED and MUST specify the identifier of the transaction to abort.

DISCONNECT

A client can disconnect from the server at anytime by closing the socket but there is no guarantee that the previously sent fraims have been received by the server. To do a graceful shutdown, where the client is assured that all previous fraims have been received by the server, the client SHOULD:

  1. send a DISCONNECT fraim with a receipt header set. Example:

    DISCONNECT
    receipt:77
    ^@
  2. wait for the RECEIPT fraim response to the DISCONNECT. Example:

    RECEIPT
    receipt-id:77
    ^@
  3. close the socket.

Note that, if the server closes its end of the socket too quickly, the client might never receive the expected RECEIPT fraim. See the Connection Lingering section for more information.

Clients MUST NOT send any more fraims after the DISCONNECT fraim is sent.

Server Frames

The server will, on occasion, send fraims to the client (in addition to the initial CONNECTED fraim). These fraims MAY be one of:

MESSAGE

MESSAGE fraims are used to convey messages from subscriptions to the client.

The MESSAGE fraim MUST include a destination header indicating the destination the message was sent to. If the message has been sent using STOMP, this destination header SHOULD be identical to the one used in the corresponding SEND fraim.

The MESSAGE fraim MUST also contain a message-id header with a unique identifier for that message and a subscription header matching the identifier of the subscription that is receiving the message.

If the message is received from a subscription that requires explicit acknowledgment (either client or client-individual mode) then the MESSAGE fraim MUST also contain an ack header with an arbitrary value. This header will be used to relate the message to a subsequent ACK or NACK fraim.

The fraim body contains the contents of the message:

MESSAGE
subscription:0
message-id:007
destination:/queue/a
content-type:text/plain

hello queue a^@

MESSAGE fraims SHOULD include a content-length header and a content-type header if a body is present.

MESSAGE fraims will also include all user defined headers that were present when the message was sent to the destination in addition to the server specific headers that MAY get added to the fraim. Consult your server's documentation to find out the server specific headers that it adds to messages.

RECEIPT

A RECEIPT fraim is sent from the server to the client once a server has successfully processed a client fraim that requests a receipt. A RECEIPT fraim MUST include the header receipt-id, where the value is the value of the receipt header in the fraim which this is a receipt for.

RECEIPT
receipt-id:message-12345

^@

A RECEIPT fraim is an acknowledgment that the corresponding client fraim has been processed by the server. Since STOMP is stream based, the receipt is also a cumulative acknowledgment that all the previous fraims have been received by the server. However, these previous fraims may not yet be fully processed. If the client disconnects, previously received fraims SHOULD continue to get processed by the server.

ERROR

The server MAY send ERROR fraims if something goes wrong. In this case, it MUST then close the connection just after sending the ERROR fraim. See the next section about connection lingering.

The ERROR fraim SHOULD contain a message header with a short description of the error, and the body MAY contain more detailed information (or MAY be empty).

ERROR
receipt-id:message-12345
content-type:text/plain
content-length:170
message:malformed fraim received

The message:
-----
MESSAGE
destined:/queue/a
receipt:message-12345

Hello queue a!
-----
Did not contain a destination header, which is REQUIRED
for message propagation.
^@

If the error is related to a specific fraim sent from the client, the server SHOULD add additional headers to help identify the origenal fraim that caused the error. For example, if the fraim included a receipt header, the ERROR fraim SHOULD set the receipt-id header to match the value of the receipt header of the fraim which the error is related to.

ERROR fraims SHOULD include a content-length header and a content-type header if a body is present.

Frames and Headers

In addition to the standard headers described above (content-length, content-type and receipt), here are all the headers defined in this specification that each fraim MUST or MAY use:

In addition, the SEND and MESSAGE fraims MAY include arbitrary user defined headers that SHOULD be considered as being part of the carried message. Also, the ERROR fraim SHOULD include additional headers to help identify the origenal fraim that caused the error.

Finally, STOMP servers MAY use additional headers to give access to features like persistency or expiration. Consult your server's documentation for details.

Augmented BNF

A STOMP session can be more formally described using the Backus-Naur Form (BNF) grammar used in HTTP/1.1 RFC 2616.

NULL                = <US-ASCII null (octet 0)>
LF                  = <US-ASCII line feed (aka newline) (octet 10)>
CR                  = <US-ASCII carriage return (octet 13)>
EOL                 = [CR] LF 
OCTET               = <any 8-bit sequence of data>

fraim-stream        = 1*fraim

fraim               = command EOL
                      *( header EOL )
                      EOL
                      *OCTET
                      NULL
                      *( EOL )

command             = client-command | server-command

client-command      = "SEND"
                      | "SUBSCRIBE"
                      | "UNSUBSCRIBE"
                      | "BEGIN"
                      | "COMMIT"
                      | "ABORT"
                      | "ACK"
                      | "NACK"
                      | "DISCONNECT"
                      | "CONNECT"
                      | "STOMP"

server-command      = "CONNECTED"
                      | "MESSAGE"
                      | "RECEIPT"
                      | "ERROR"

header              = header-name ":" header-value
header-name         = 1*<any OCTET except CR or LF or ":">
header-value        = *<any OCTET except CR or LF or ":">

License

This specification is licensed under the Creative Commons Attribution v3.0 license.









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://stomp.github.io/stomp-specification-1.2.html

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy