Movatterモバイル変換


[0]ホーム

URL:


STOMP Protocol Specification, Version 1.1

Abstract

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

STOMP has been in active use for several years and is supported by manymessage brokers and client libraries. This specification defines the STOMP 1.1protocol and is an update toSTOMP 1.0.

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

Overview

Background

STOMP arose from a need to connect to enterprise message brokers fromscripting languages such as Ruby, Python and Perl. In such anenvironment it is typically logically simple operations that arecarried 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 AMQPand implementation specific wire protocols used in JMS brokers suchas OpenWire. It distinguishes itself by covering a small subset ofcommonly used messaging operations rather than providing acomprehensive messaging API.

More recently STOMP has matured into a protocol which can be used pastthese simple use cases in terms of the wire-level features it nowoffers, but still maintains its core design principles of simplicityand interoperability.

Protocol Overview

STOMP is a frame based protocol, with frames modelled on HTTP. A frameconsists of a command, a set of optional headers and an optional body. STOMPis text based but also allows for the transmission of binary messages. Thedefault encoding for STOMP is UTF-8, but it supports the specification ofalternative encodings for message bodies.

A STOMP server is modelled as a set of destinations to which messages can besent. The STOMP protocol treats destinations as opaque string and their syntaxis server implementation specific. Additionally STOMP does not define what thedelivery semantics of destinations should be. The delivery, or “messageexchange”, semantics of destinations can vary from server to server and evenfrom destination to destination. This allows servers to be creative with thesemantics 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.1 is designed to be backwards compatible with STOMP 1.0 whileintroducing several new features not present in STOMP 1.0:

Design Philosophy

The main philosophies driving the design of STOMP are simplicity andinteroperability.

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

In this specification we will note features of servers which are notexplicitly defined by STOMP 1.1. You should consult your STOMP server'sdocumentation 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 beinterpreted as described in RFC 2119.

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

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

STOMP Frames

STOMP is a frame based protocol which assumes a reliable 2-way streamingnetwork protocol (such as TCP) underneath. The client and server willcommunicate using STOMP frames sent over the stream. A frame's structurelooks like:

COMMANDheader1:value1header2:value2Body^@

The frame starts with a command string terminated by a newline. Following thecommand are one or more header entries in<key>:<value> format. Each headerentry is terminated by a newline. A blank line indicates the end of theheaders and the beginning of the body. The body is then followed by the nullbyte (0x00). The examples in this document will use^@, control-@ in ASCII,to represent the null byte. The null byte can be optionally followed bymultiple newlines. For more details, on how to parse STOMP frames, see theAugmented 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 frames except theCONNECTandCONNECTED frames will also escape any colon or newline octets found inthe resulting UTF-8 encoded headers.

Escaping is needed to allow header keys and values to contain those frameheader delimiting octets as values. TheCONNECT andCONNECTED frames do notescape the colon or newline octets in order to remain backward compatible withSTOMP 1.0.

C style string literal escapes are used to encode any colons and newlines thatare found within the UTF-8 encoded headers. When decoding frame headers, thefollowing transformations MUST be applied:

Undefined escape sequences such as\r (octet 92 and 114) MUST be treated asa fatal protocol error. Conversely when encoding frame headers, the reversetransformation MUST be applied.

Only theSEND,MESSAGE, andERROR frames can have a body. All otherframes MUST NOT have a body.

The STOMP 1.0 specification included many example frames with padding in theheaders and many servers and clients were implemented to trim or pad headervalues. This causes problems if applications want to send headers that SHOULDnot get trimmed. In STOMP 1.1, clients and servers MUST never trim or padheaders with spaces.

Size Limits

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

If these limits are exceeded the server SHOULD send the client anERRORframe and disconnect the client.

Repeated Header Entries

Since messaging systems can be organized in store and forward topologies,similar to SMTP, a message may traverse several messaging servers beforereaching a consumer. The intermediate server MAY 'update' header values byeither prepending headers to the message or modifying a header in-place inthe message.

If the client receives repeated frame header entries, only the first headerentry SHOULD be used as the value of header entry. Subsequent values are onlyused to maintain a history of state changes of the header. For example, if theclient receives:

MESSAGEfoo:Worldfoo:Hello^@

The value of thefoo header is justWorld.

Connecting

A STOMP client initiates the stream or TCP connection to the server by sendingtheCONNECT frame:

CONNECTaccept-version:1.1host:stomp.github.org^@

If the server accepts the connection attempt it will respond with aCONNECTED frame:

CONNECTEDversion:1.1^@

The server can reject any connection attempt. The server SHOULD respond backwith anERROR frame listing why the connection was rejected and then closethe connection. STOMP servers MUST support clients which rapidly connect anddisconnect. This implies a server will likely only allow closed connectionsto linger for short time before the connection is reset. This means that aclient may not receive theERROR frame before the socket is reset.

CONNECT or STOMP Frame

STOMP servers SHOULD handle aSTOMP frame in the same manner as aCONNECTframe. STOMP 1.1 clients SHOULD continue to use theCONNECT command toremain backward compatible with STOMP 1.0 servers.

Clients that use theSTOMP frame instead of theCONNECT frame will onlybe able to connect to STOMP 1.1 servers but the advantage is that a protocolsniffer/discriminator will be able to differentiate the STOMP connection froman HTTP connection.

STOMP 1.1 clients MUST set the following headers:

STOMP 1.1 clients MAY set the following headers:

CONNECTED Frame

STOMP 1.1 servers MUST set the following headers:

STOMP 1.1 servers MAY set the following headers:

Protocol Negotiation

From STOMP 1.1 and onwards, theCONNECT frame MUST include theaccept-version header. It SHOULD be set to a comma separated list ofincrementing STOMP protocol versions that the client supports. If theaccept-version header is missing, it means that the client only supportsversion 1.0 of the protocol.

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

For example, if the client sends:

CONNECTaccept-version:1.0,1.1,2.0host:stomp.github.org^@

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

CONNECTEDversion:1.1^@

If the client and server do not share any common protocol versions, then theserver SHOULD respond with anERROR frame similar to:

ERRORversion:1.2,2.1content-type:text/plainSupported protocol versions are 1.2 2.1^@

Once Connected

A client MAY send a frame not in this list, but for such a frame aSTOMP 1.1 server MAY respond with anERROR frame.

Client Frames

SEND

TheSEND frame sends a message to a destination in the messaging system. Ithas one REQUIRED header,destination, which indicates where to send themessage. The body of theSEND frame is the message to be sent. For example:

SENDdestination:/queue/acontent-type:text/plainhello queue a^@

This sends a message to a destination named/queue/a. Note that STOMP treatsthis destination as an opaque string and no delivery semantics are assumed bythe name of a destination. You should consult your STOMP server'sdocumentation to find out how to construct a destination name which gives youthe delivery semantics that your application needs.

The reliability semantics of the message are also server specific and willdepend on the destination value being used and the other message headerssuch as thetransaction header or other server specific message headers.

SEND supports atransaction header which allows for transactional sends.

SEND frames SHOULD include acontent-length header and acontent-type header if a body is present.

An application MAY add any arbitrary user defined headers to theSEND frame.User defined headers are typically used to allow consumers to filtermessages based on the application defined headers using a selectoron aSUBSCRIBE frame. The user defined headers MUST be passed throughin theMESSAGE frame.

If the server cannot successfully process theSEND frame for any reason,the server MUST send the client anERROR frame and disconnect the client.

SUBSCRIBE

TheSUBSCRIBE frame is used to register to listen to a given destination.Like theSEND frame, theSUBSCRIBE frame requires adestination headerindicating the destination to which the client wants to subscribe. Anymessages received on the subscribed destination will henceforth be deliveredasMESSAGE frames from the server to the client. Theack header controlsthe message acknowledgement mode.

Example:

SUBSCRIBEid:0destination:/queue/fooack:client^@

If the server cannot successfully create the subscription,the server MUST send the client anERROR frame and disconnect the client.

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

SUBSCRIBE id Header

Anid header MUST be included in the frame to uniquely identify the subscription within theSTOMP connection session. Since a single connection can have multiple opensubscriptions with a server, theid header allows the client and server torelate subsequentACK,NACK orUNSUBSCRIBE frames to the originalsubscription.

SUBSCRIBE ack Header

The valid values for theack header areauto,client, orclient-individual. If the header is not set, it defaults toauto.

When theack mode isauto, then the client does not need to send theserverACK frames for the messages it receives. The server will assume theclient has received the message as soon as it sends it to the client.This acknowledgment mode can cause messages being transmitted to the clientto get dropped.

When theack mode isclient, then the client MUST send the serverACK frames for the messages it processes. If the connection fails before aclient sends anACK for the message the server will assume the message hasnot been processed and MAY redeliver the message to another client. TheACKframes sent by the client will be treated as a cumulativeACK. This means theACK operates on the message specified in theACK frameand all messages sent to the subscription before theACK-ed message.

When theack mode isclient-individual, the ack mode operates justlike theclient ack mode except that theACK orNACK frames sent by theclient are not cumulative. This means that anACK orNACK for asubsequent message MUST NOT cause a previous message to get acknowledged.

UNSUBSCRIBE

TheUNSUBSCRIBE frame is used to remove an existing subscription. Once thesubscription is removed the STOMP connections will no longer receive messagesfrom that destination. It requires that theid header matches theidvalue of previousSUBSCRIBE operation. Example:

UNSUBSCRIBEid:0^@

ACK

ACK is used to acknowledge consumption of a message from a subscriptionusingclient orclient-individual acknowledgment. Any messages receivedfrom such a subscription will not be considered to have been consumed untilthe message has been acknowledged via anACK or aNACK.

ACK has two REQUIRED headers:message-id, which MUST contain a valuematching themessage-id for theMESSAGE being acknowledged andsubscription, which MUST be set to match the value of the subscription'sid header. Optionally, atransaction header MAY be specified, indicatingthat the message acknowledgment SHOULD be part of the named transaction.

ACKsubscription:0message-id:007transaction:tx1^@

NACK

NACK is the opposite ofACK. It is used to tell the server that theclient did not consume the message. The server can then either send themessage 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 asACK:message-id (mandatory),subscription (mandatory) andtransaction (OPTIONAL).

NACK applies either to one single message (if the subscription's ack modeisclient-individual) or to all messages sent before and not yetACK'edorNACK'ed.

BEGIN

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

BEGINtransaction:tx1^@

Thetransaction header is REQUIRED, and the transaction identifier will beused forSEND,COMMIT,ABORT,ACK, andNACK frames to bind them tothe named transaction.

Any started transactions which have not been committed will be implicitlyaborted if the client sends aDISCONNECT frame or if the TCP connectionfails for any reason.

COMMIT

COMMIT is used to commit a transaction in progress.

COMMITtransaction:tx1^@

Thetransaction header is REQUIRED and MUST specify the id of the transaction tocommit!

ABORT

ABORT is used to roll back a transaction in progress.

ABORTtransaction:tx1^@

Thetransaction header is REQUIRED and MUST specify the id of the transaction toabort!

DISCONNECT

A client can disconnect from the server at anytime by closing the socket butthere is no guarantee that the previously sent frames have been received bythe server. To do a graceful shutdown, where the client is assured that allprevious frames have been received by the server, the client SHOULD:

  1. send aDISCONNECT frame with areceipt header set. Example:

    DISCONNECTreceipt:77^@
  2. wait for theRECEIPT frame response to theDISCONNECT. Example:

    RECEIPTreceipt-id:77^@
  3. close the socket.

Clients MUST NOT send any more frames after theDISCONNECT frame is sent.

Standard Headers

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

Header content-length

TheSEND,MESSAGE andERROR frames SHOULD include acontent-lengthheader if a frame body is present. If a frame's body contains NULL octets, theframe MUST include acontent-length header. The header is a byte count forthe length of the message body. If acontent-length header is included, thisnumber of bytes MUST be read, regardless of whether or not there are nullcharacters in the body. The frame still needs to be terminated with a nullbyte.

Header content-type

TheSEND,MESSAGE andERROR frames SHOULD include acontent-typeheader if a frame body is present. It SHOULD be set to a mime type whichdescribes the format of the body to help the receiver of the frame interpretit's contents. If thecontent-type header is not set, the receiver SHOULDconsider the body to be a binary blob.

The implied text encoding for mime types starting withtext/ is UTF-8. Ifyou are using a text based mime type with a different encoding then youSHOULD append;charset=<encoding> to the mime type. For example,text/html;charset=utf-16 SHOULD be used if your sending an html body inUTF-16 encoding. The;charset=<encoding> SHOULD also get appended to anynontext/ mime types which can be interpreted as text. A good example ofthis would be a UTF-8 encoded XML. It'scontent-type SHOULD get set toapplication/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 isRECOMMENDED that text based content be encoded with UTF-8.

Header receipt

Any client frame other thanCONNECT MAY specify areceiptheader with an arbitrary value. This will cause the server to acknowledgereceipt of the frame with aRECEIPT frame which contains the value of thisheader as the value of thereceipt-id header in theRECEIPT frame.

SENDdestination:/queue/areceipt:message-12345hello queue a^@

Server Frames

The server will, on occasion, send frames to the client (in addition to theinitialCONNECTED frame). These frames MAY be one of:

MESSAGE

MESSAGE frames are used to convey messages from subscriptions to theclient. TheMESSAGE frame will include adestination header indicatingthe destination the message was sent to. It will also contain amessage-idheader with a unique identifier for that message. Thesubscription headerwill be set to match theid header of the subscription that is receivingthe message. The frame body contains the contents of the message:

MESSAGEsubscription:0message-id:007destination:/queue/acontent-type:text/plainhello queue a^@

MESSAGE frames SHOULD include acontent-length header and acontent-type header if a body is present.

MESSAGE frames will also include all user defined headers that were presentwhen the message was sent to the destination in addition to the serverspecific headers that MAY get added to the frame. Consult your server'sdocumentation to find out the server specific headers that it adds tomessages.

RECEIPT

ARECEIPT frame is sent from the server to the client once a server hassuccessfully processed a client frame that requests a receipt. ARECEIPTframe will include the headerreceipt-id, where the value is the value ofthereceipt header in the frame which this is a receipt for.

RECEIPTreceipt-id:message-12345^@

The receipt body will be empty.

ERROR

The server MAY sendERROR frames if something goes wrong. The error frameSHOULD contain amessage header with a short description of the error, andthe body MAY contain more detailed information (or MAY be empty).

ERRORreceipt-id:message-12345content-type:text/plaincontent-length:171message: malformed frame receivedThe message:-----MESSAGEdestined:/queue/areceipt:message-12345Hello queue a!-----Did not contain a destination header, which is REQUIREDfor message propagation.^@

If the error is related to specific frame sent from the client, the serverSHOULD add additional headers to help identify the original frame that causedthe error. For example, if the frame included a receipt header, theERRORframe SHOULD set thereceipt-id header to match the value of thereceiptheader of the frame which the error is related to.

ERROR frames SHOULD include acontent-length header and acontent-type header if a body is present.

Heart-beating

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

In order to enable heart-beating, each party has to declare what it can doand what it would like the other party to do. This happens at the verybeginning of the STOMP session, by adding aheart-beat header to theCONNECT andCONNECTED frames.

When used, theheart-beat header MUST contain two positive integersseparated by a comma.

The first number represents what the sender of the frame can do (outgoingheart-beats):

The second number represents what the sender of the frame would liketo get (incoming heart-beats):

Theheart-beat header is OPTIONAL. A missingheart-beat header MUST betreated the same way as a “heart-beat:0,0” header, that is: the party cannotsend and does not want to receive heart-beats.

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

More formally, the initial frames look like:

CONNECTheart-beat:<cx>,<cy>CONNECTEDheart-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 networkconnection is an indication that the remote end is alive. In a givendirection, if heart-beats are expected every<n> milliseconds:

Augmented BNF

A STOMP session can be more formally described using theBackus-Naur Form (BNF) grammar used in HTTP/1.1rfc2616.

LF                  = <US-ASCII new line (line feed) (octet 10)>OCTET               = <any 8-bit sequence of data>NULL                = <octet 0>frame-stream        = 1*frameframe               = command LF                      *( header LF )                      LF                      *OCTET                      NULL                      *( LF )command             = client-command | server-commandclient-command      = "SEND"                      | "SUBSCRIBE"                      | "UNSUBSCRIBE"                      | "BEGIN"                      | "COMMIT"                      | "ABORT"                      | "ACK"                      | "NACK"                      | "DISCONNECT"                      | "CONNECT"                      | "STOMP"server-command      = "CONNECTED"                      | "MESSAGE"                      | "RECEIPT"                      | "ERROR"header              = header-name ":" header-valueheader-name         = 1*<any OCTET except LF or ":">header-value        = *<any OCTET except LF or ":">

License

This specification is licensed under theCreative Commons Attribution v2.5license.


[8]ページ先頭

©2009-2026 Movatter.jp