0Pricing
WebSockets & Real-Time Systems with Spring · Lección

Configuración del broker relay de STOMP

Sustituya el broker simple en memoria por un broker relay de STOMP para que Spring reenvíe los mensajes a un broker real como RabbitMQ y permita el escalado horizontal.

Configuración del broker relay de STOMP es una lección gratuita de WebSockets & Real-Time Systems with Spring en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de WebSockets & Real-Time Systems with Spring, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de WebSockets & Real-Time Systems with Spring incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

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_stomp

Application vs Broker Destinations

Keep the prefixes distinct:

  • /app → routed to your @MessageMapping controllers
  • /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
  • enableStompBrokerRelay forwards to RabbitMQ/ActiveMQ over STOMP
  • Enable the broker's STOMP plugin (port 61613)
  • Keep /app for controllers, /topic and /queue for the broker
  • The relay gives clustering, persistence, and durable subscriptions

Preguntas frecuentes

¿La lección «Configuración del broker relay de STOMP» es gratis?

Sí — el texto completo de «Configuración del broker relay de STOMP» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de WebSockets & Real-Time Systems with Spring, actualiza a CoddyKit PRO. El curso de WebSockets & Real-Time Systems with Spring incluye 4 lecciones en total.

¿Qué aprenderé en «Configuración del broker relay de STOMP»?

Sustituya el broker simple en memoria por un broker relay de STOMP para que Spring reenvíe los mensajes a un broker real como RabbitMQ y permita el escalado horizontal. Practicas WebSockets & Real-Time Systems with Spring con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar WebSockets & Real-Time Systems with Spring?

No se requiere experiencia previa. WebSockets & Real-Time Systems with Spring en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.

¿Cuánto tiempo toma la lección «Configuración del broker relay de STOMP»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de WebSockets & Real-Time Systems with Spring?

Sí. Cada lección de WebSockets & Real-Time Systems with Spring incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Necesidad de brokers de mensajes externos
  2. Integración con RabbitMQ/Kafka
  3. Arquitecturas WebSocket distribuidas
  4. Configuración del broker relay de STOMP
← Volver a WebSockets & Real-Time Systems with Spring