STOMP-Broker-Relay konfigurieren
Ersetzen Sie den einfachen In-Memory-Broker durch ein STOMP-Broker-Relay, damit Spring Nachrichten zur horizontalen Skalierung an einen echten Broker wie RabbitMQ weiterleitet.
STOMP-Broker-Relay konfigurieren ist eine kostenlose WebSockets & Real-Time Systems with Spring-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des WebSockets & Real-Time Systems with Spring-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der WebSockets & Real-Time Systems with Spring-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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
Lerne WebSockets & Real-Time Systems with Spring mit einem KI-Tutor — kostenlos
Schreibe und führe echten Code in deinem Browser aus, bekomme sofortige Hilfe von einem 24/7 KI-Tutor und setze dein Lernen im Web oder in der App fort.
- Kurse
- 12
- Lektionen
- 48
Häufig gestellte Fragen
Ist die Lektion „STOMP-Broker-Relay konfigurieren“ kostenlos?
Ja — der vollständige Text von „STOMP-Broker-Relay konfigurieren“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des WebSockets & Real-Time Systems with Spring-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der WebSockets & Real-Time Systems with Spring-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „STOMP-Broker-Relay konfigurieren“?
Ersetzen Sie den einfachen In-Memory-Broker durch ein STOMP-Broker-Relay, damit Spring Nachrichten zur horizontalen Skalierung an einen echten Broker wie RabbitMQ weiterleitet. Du übst WebSockets & Real-Time Systems with Spring mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um WebSockets & Real-Time Systems with Spring zu starten?
Keine Vorkenntnisse erforderlich. WebSockets & Real-Time Systems with Spring auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „STOMP-Broker-Relay konfigurieren“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser WebSockets & Real-Time Systems with Spring-Lektion Code schreiben und ausführen?
Ja. Jede WebSockets & Real-Time Systems with Spring-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Notwendigkeit externer Message-Broker
- RabbitMQ/Kafka integrieren
- Verteilte WebSocket-Architekturen
- STOMP-Broker-Relay konfigurieren