0Pricing
WebSockets & Real-Time Systems with Spring · Lesson

Configuring the STOMP Broker Relay

Replace the in-memory simple broker with a STOMP broker relay so Spring forwards messages to a real broker like RabbitMQ for horizontal scaling.

Configuring the STOMP Broker Relay is a free WebSockets & Real-Time Systems with Spring lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the WebSockets & Real-Time Systems with Spring learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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

Frequently asked questions

Is the “Configuring the STOMP Broker Relay” lesson free?

Yes — the full text of “Configuring the STOMP Broker Relay” is free to read here on the web, and the WebSockets & Real-Time Systems with Spring course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the WebSockets & Real-Time Systems with Spring course, upgrade to CoddyKit PRO.

What will I learn in “Configuring the STOMP Broker Relay”?

Replace the in-memory simple broker with a STOMP broker relay so Spring forwards messages to a real broker like RabbitMQ for horizontal scaling. You practise WebSockets & Real-Time Systems with Spring with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start WebSockets & Real-Time Systems with Spring?

No prior experience is required. WebSockets & Real-Time Systems with Spring on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Configuring the STOMP Broker Relay” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this WebSockets & Real-Time Systems with Spring lesson?

Yes. Every WebSockets & Real-Time Systems with Spring lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Need for External Message Brokers
  2. Integrating with RabbitMQ/Kafka
  3. Distributed WebSocket Architectures
  4. Configuring the STOMP Broker Relay
← Back to WebSockets & Real-Time Systems with Spring