0Pricing
WebSockets & Real-Time Systems with Spring · 강의

STOMP 프로토콜 소개

구조화된 메시지 라우팅과 구독에 원시 WebSockets보다 STOMP가 유용한 이유를 이해합니다.

STOMP 프로토콜 소개은(는) CoddyKit의 무료 WebSockets & Real-Time Systems with Spring 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 WebSockets & Real-Time Systems with Spring 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. WebSockets & Real-Time Systems with Spring 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Meet STOMP: Structured Messaging

Welcome to STOMP! When building real-time apps with WebSockets, you often need more than just raw data transfer. You need structure, routing, and a way to subscribe to specific messages.

STOMP (Simple Text Oriented Messaging Protocol) provides this structure. Think of it as a higher-level protocol that sits on top of WebSockets.

Raw WebSockets: Limitations

With raw WebSockets, clients and servers send arbitrary bytes or strings. If you want to send a "chat message" or a "user joined" event, you have to define your own rules:

  • How do I know what kind of message it is?
  • Who should receive this message?
  • What if I want to send data in a specific format like JSON?

Without a protocol, you'd implement all this manually.

STOMP: A Common Language

STOMP solves these problems by defining a standard way to send and receive messages. It's like agreeing on a common language for your real-time communication.

  • It's text-based, making it easy to debug.
  • It uses a simple frame format for all communication.
  • It supports common messaging patterns like publish-subscribe.

Understanding STOMP Frames

All communication in STOMP happens via "frames." A STOMP frame consists of three main parts:

  • COMMAND: What action is being performed (e.g., SEND, SUBSCRIBE, CONNECT).
  • HEADERS: Key-value pairs providing additional info (e.g., destination, content-type).
  • BODY: The actual message payload.

These parts are separated by newlines.

First Frame: CONNECT

When a client wants to establish a STOMP connection over a WebSocket, it sends a CONNECT frame. This tells the server it wants to speak STOMP. Note the empty line before the null byte (^@) which terminates the frame.

Here's what a simple CONNECT frame looks like:

CONNECT
accept-version:1.2
host:localhost

Server's Reply: CONNECTED

If the server accepts the connection, it responds with a CONNECTED frame. This confirms the STOMP session is ready. It also includes headers like the server's version and session ID. Remember, frames end with a null byte (^@).

CONNECTED
version:1.2
session:session-1234
server:Spring

Sending Messages: The SEND Frame

To send a message, clients use the SEND command. This frame requires a destination header, which tells the STOMP broker where to route the message. The message body contains the actual data, often JSON. Don't forget the null byte (^@) terminator!

SEND
destination:/app/chat
content-type:application/json

{"user":"Alice","message":"Hello, everyone!"}

Receiving Messages: SUBSCRIBE

Clients receive messages by using the SUBSCRIBE command. They specify a destination to listen to and an id for their subscription. The server then sends MESSAGE frames to this client when new data arrives for that destination. Frames are always null-byte (^@) terminated.

SUBSCRIBE
id:sub-0
destination:/topic/public

STOMP Destinations: Routing

STOMP uses destinations to route messages. These are like addresses. The most common types are:

  • Topics (/topic/...): For broadcast messages, where all subscribers receive a copy. Great for chat rooms.
  • Queues (/queue/...): For point-to-point messages, typically handled by one consumer. Useful for private messages or task queues.

This built-in routing is a major advantage over raw WebSockets.

Why Use STOMP?

STOMP provides significant benefits for real-time applications:

  • Structured Messaging: Standardized frame format.
  • Message Routing: Built-in support for topics and queues.
  • Subscription Model: Easy for clients to listen to specific events.
  • Simpler Client-Side: Many client libraries exist that handle STOMP frames, simplifying development.

It adds a robust layer for complex messaging patterns.

Check Your Understanding

Which of the following is a primary benefit of using STOMP over raw WebSockets?

Lesson Recap: Introducing STOMP

In this lesson, you learned about the STOMP protocol and why it's essential for structured real-time communication over WebSockets.

  • Raw WebSockets lack built-in message structure and routing.
  • STOMP provides a simple, text-based frame format (COMMAND, HEADERS, BODY).
  • Key STOMP commands include CONNECT, CONNECTED, SEND, and SUBSCRIBE.
  • It enables powerful features like topic-based broadcasting and queue-based point-to-point messaging.

Next, we'll see how to integrate STOMP with Spring Boot!

자주 묻는 질문

“STOMP 프로토콜 소개” 강의는 무료인가요?

네 — “STOMP 프로토콜 소개” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 WebSockets & Real-Time Systems with Spring 강의 전체를 잠금 해제할 수 있습니다. WebSockets & Real-Time Systems with Spring 강의에는 총 4개의 강의가 포함되어 있습니다.

“STOMP 프로토콜 소개”에서 뭘 배우나요?

구조화된 메시지 라우팅과 구독에 원시 WebSockets보다 STOMP가 유용한 이유를 이해합니다. 브라우저에서 직접 실행하는 실습 코드로 WebSockets & Real-Time Systems with Spring을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

WebSockets & Real-Time Systems with Spring을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 WebSockets & Real-Time Systems with Spring은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“STOMP 프로토콜 소개” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 WebSockets & Real-Time Systems with Spring 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 WebSockets & Real-Time Systems with Spring 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. STOMP 프로토콜 소개
  2. Spring에서 STOMP 구성하기
  3. STOMP 메시지 송수신
  4. Spring Security로 STOMP 엔드포인트 보호
← WebSockets & Real-Time Systems with Spring(으)로 돌아가기