Konfiguracja STOMP Broker Relay
Zastąpią Państwo prosty broker działający w pamięci mechanizmem STOMP broker relay, aby Spring przekazywał wiadomości do rzeczywistego brokera, takiego jak RabbitMQ, umożliwiając skalowanie poziome.
Konfiguracja STOMP Broker Relay to bezpłatna lekcja WebSockets & Real-Time Systems with Spring na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej WebSockets & Real-Time Systems with Spring, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs WebSockets & Real-Time Systems with Spring zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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
Często zadawane pytania
Czy lekcja „Konfiguracja STOMP Broker Relay” jest bezpłatna?
Tak — pełny tekst „Konfiguracja STOMP Broker Relay” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu WebSockets & Real-Time Systems with Spring, przejdź na CoddyKit PRO. Kurs WebSockets & Real-Time Systems with Spring zawiera 4 lekcji w sumie.
Co nauczysz się w „Konfiguracja STOMP Broker Relay”?
Zastąpią Państwo prosty broker działający w pamięci mechanizmem STOMP broker relay, aby Spring przekazywał wiadomości do rzeczywistego brokera, takiego jak RabbitMQ, umożliwiając skalowanie poziome. Ćwiczysz WebSockets & Real-Time Systems with Spring z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć WebSockets & Real-Time Systems with Spring?
Nie wymagamy żadnego doświadczenia. WebSockets & Real-Time Systems with Spring w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.
Ile czasu zajmuje lekcja „Konfiguracja STOMP Broker Relay”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji WebSockets & Real-Time Systems with Spring?
Tak. Każda lekcja WebSockets & Real-Time Systems with Spring zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Potrzeba zewnętrznych brokerów wiadomości
- Integracja z RabbitMQ/Kafka
- Rozproszone architektury WebSocket
- Konfiguracja STOMP Broker Relay