Post

STOMP Protocol

STOMP Protocol

This post was migrated from Tistory. You can find the original here.

Stomp Design

Simple Text Oriented Messaging Protocol

The main philosophy behind STOMP’s design is simplicity and interoperability, and it’s designed as a lightweight protocol that can be easily implemented on both the client and server side in a variety of languages. This also means the protocol doesn’t impose many constraints on server architecture, and features like destination naming, reliability, and semantics can vary by implementation.

Stomp Frame

STOMP is a protocol built on top of a reliable, bidirectional streaming network protocol (such as TCP), and it communicates based on frames.

Clients and servers communicate using STOMP frames sent over the stream, and a frame has the following structure.

1
2
3
4
5
COMMAND
header1:value1
header2:value2

Body^@

A NULL octet comes at the end of the body. In the spec document, the NULL octet is represented as ^@.

A NULL octet is an 8-bit block of data represented as zero, i.e., an octet with an 8-bit value of 0 — such as 0x00 in data or 00000000 in binary.
This is often used to mark the end of a string or piece of data. Escape sequences used for this across various languages include \0, \000, \x00, \z, \u0000, and so on.

Encoding

COMMAND and HEADERS are encoded in UTF-8, and in every frame except CONNECT and CONNECTED, carriage return, line feed, and colon characters present in headers must be escaped. The same rules must apply when decoding, and any undefined escape sequence must be treated as a fatal protocol error.

  • \r (octet 92 and 114) translates to carriage return (octet 13)
  • \n (octet 92 and 110) translates to line feed (octet 10)
  • \c (octet 92 and 99) translates to : (octet 58)
  • \ (octet 92 and 92) translates to \ (octet 92)

COMMAND

  • Client Frame Command - SEND, SUBSCRIBE, UNSUBSCRIBE, ACK, NACK, BEGIN, COMMIT, ABORT, DISCONNECT
  • Server Frame Command - MESSAGE, RECEIPT, ERROR

Body

Only the SEND, MESSAGE, and ERROR frames have a body.
\

Standard Headers

  • content-length
    This header can be included in any frame. It represents the number of octets in the body’s length, and if this header is present, that many octets must be read regardless of whether there’s a NULL octet in the body. The frame must still be terminated with a NULL octet regardless.

    SEND, MESSAGE, and ERROR frames that have a body are recommended to include this header for ease of parsing, and if the body contains a NULL octet, this header must be included.
  • *content-type*If this header is present, the body is treated as the given MIME type; if it’s absent, the body is treated as a blob.
    If the MIME type is text, the default is text/UTF-8. If a text-based MIME type uses a different encoding, ;charset= must be appended. For example, if an HTML body is sent encoded as UTF-16, it can be specified as text/html;charset=utf-16.\ \ As long as it can be interpreted as text, MIME types like application/xml;charset=utf-8 (XML encoded in UTF-8) are also fine.\ \ All STOMP clients and servers must support UTF-8 encoding and decoding. So to maximize interoperability across heterogeneous computing environments, it's recommended to encode text-based content as UTF-8. \
  • receipt** Any frame except CONNECT can include a receipt:<arbitrary value> header. This causes the server to acknowledge the processing of the client frame with a RECEIPT frame. (original quote — “This will cause the server to acknowledge the processing of the client frame with a RECEIPT frame”)
1
2
3
4
DISCONNECT
receipt:close-1

NULL

When a client sends a DISCONNECT frame with a receipt header specified,

1
2
3
4
RECEIPT
receipt-id:disconnect-123

NULL

the server responds with a RECEIPT frame like the one above.

1
2
3
4
5
ERROR
message:Session closed.
content-length:0

NULL

If DISCONNECT is sent without a receipt header, the server responds with an ERROR frame along with a session-closed message as shown above.

1
2
3
4
5
SEND
destination:/queue/a
receipt:message-12345

hello queueNULL

Checked with @stomp/stompjs

When a receipt header is included in a SEND frame, no RECEIPT frame response is seen. (Not seen in either JMeter or @stomp/stompjs.)

Is it possible that Spring STOMP’s default configuration blocks RECEIPT responses only for SEND frames?


To be continued

References

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

https://en.wikipedia.org/wiki/Null_character

[Null character - Wikipedia

From Wikipedia, the free encyclopedia Control character whose bits are all 0 The null character (also null terminator) is a control character with the value zero.[1][2][3][4] It is present in many character sets, including those defined by the Baudot and I

en.wikipedia.org](https://en.wikipedia.org/wiki/Null_character)

https://blog.paimon.studio/54

[[WebSocket] Stomp 프로토콜 1.2 명세 번역

주의: 이 문서는 명세서 원본이 아닙니다. 문서를 읽어보면서 개략적으로 개인 공부를 위해 한글로 옮긴 것입니다, 명세의 모든 문장을 포함하지 않았습니다. STOMP 프로토콜 배경 STOMP는 스크립

blog.paimon.studio](https://blog.paimon.studio/54)

This post is licensed under CC BY-NC 4.0 by the author.