STOMPブローカーリレーの設定
インメモリのsimple brokerをSTOMPブローカーリレーに置き換え、SpringからRabbitMQなどの実際のブローカーへメッセージを転送して水平スケーリングする方法を学びます。
「STOMPブローカーリレーの設定」はCoddyKit上の無料WebSockets & Real-Time Systems with Springレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはWebSockets & Real-Time Systems with Spring学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 WebSockets & Real-Time Systems with Springコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Limits of the Simple Broker
The default enableSimpleBroker keeps subscriptions and message routing in memory on one JVM. It is great for demos but cannot share state across instances, so it does not scale horizontally.
Enter the Broker Relay
A STOMP broker relay tells Spring to forward messages to a dedicated broker (RabbitMQ, ActiveMQ) that speaks STOMP. The broker, not the JVM, now handles routing and fan-out.
Why This Scales
With a central broker, every Spring instance connects to the same broker. A message published on node A reaches a subscriber on node B because both share the broker's topics and queues.
Enabling the Relay
Swap enableSimpleBroker for enableStompBrokerRelay in your config, pointing at the broker host and port.
registry.enableStompBrokerRelay("/topic", "/queue")
.setRelayHost("rabbitmq")
.setRelayPort(61613)
.setClientLogin("guest")
.setClientPasscode("guest");Enabling STOMP on RabbitMQ
RabbitMQ speaks STOMP through a plugin you must enable. Port 61613 is the STOMP default.
rabbitmq-plugins enable rabbitmq_stompApplication vs Broker Destinations
Keep the prefixes distinct:
/app→ routed to your@MessageMappingcontrollers/topic,/queue→ routed straight to the broker relay
registry.setApplicationDestinationPrefixes("/app");System Connection
Spring keeps a separate system connection to the broker for server-initiated messages (e.g. convertAndSend from a service). Configure its credentials too.
relay.setSystemLogin("guest")
.setSystemPasscode("guest")
.setSystemHeartbeatSendInterval(10000);Heartbeats with the Relay
The relay maintains heartbeats with the broker to detect a dead broker connection. If the broker goes down, Spring attempts to reconnect automatically.
What the Broker Brings
A real broker adds capabilities the simple broker lacks:
- Durable subscriptions that survive restarts
- Message persistence to disk
- Cross-node fan-out for clustering
- Monitoring and management UIs
Reactive/Virtual Thread Note
The relay uses a Reactor Netty TCP client under the hood. Ensure the reactor-netty dependency is present, or the relay fails to start with a missing-class error.
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
</dependency>Graceful Degradation
If the broker is unreachable at startup, the relay keeps retrying. Design clients to handle temporary delivery gaps and reconnect, rather than assuming the broker is always up.
Quick Check
Test your relay knowledge.
Recap
You moved routing to a real broker:
- The simple broker is in-memory and single-node only
enableStompBrokerRelayforwards to RabbitMQ/ActiveMQ over STOMP- Enable the broker's STOMP plugin (port 61613)
- Keep
/appfor controllers,/topicand/queuefor the broker - The relay gives clustering, persistence, and durable subscriptions
よくある質問
「STOMPブローカーリレーの設定」レッスンは無料ですか?
はい。「STOMPブローカーリレーの設定」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、WebSockets & Real-Time Systems with Springコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 WebSockets & Real-Time Systems with Springコースには全4レッスンが含まれています。
「STOMPブローカーリレーの設定」で何を学びますか?
インメモリのsimple brokerをSTOMPブローカーリレーに置き換え、SpringからRabbitMQなどの実際のブローカーへメッセージを転送して水平スケーリングする方法を学びます。 ブラウザで直接実行するハンズオンコードでWebSockets & Real-Time Systems with Springを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
WebSockets & Real-Time Systems with Springを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのWebSockets & Real-Time Systems with Springは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「STOMPブローカーリレーの設定」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このWebSockets & Real-Time Systems with Springレッスンでコードを書いて実行できますか?
はい。すべてのWebSockets & Real-Time Systems with Springレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 外部メッセージブローカーの必要性
- RabbitMQ/Kafkaとの統合
- 分散WebSocketアーキテクチャ
- STOMPブローカーリレーの設定