Spring WebSocket Message Broker Configuration — Full Broker Setup
Fast recall
Quick revision
Core answer
Whether the candidate knows the difference between the in-memory simple broker and an external broker relay.
Using enableSimpleBroker in production — it has no persistence, no clustering, and no durability.
Mention that STOMP broker relay uses a dedicated TCP connection to the broker per Spring server instance and that RabbitMQ needs the rabbitmq_stomp plugin enabled.
Interview-ready guide
Interview answer
The in-memory simple broker is a ConcurrentHashMap in a single JVM — it works in development but breaks the moment you run two server instances. enableStompBrokerRelay() replaces it with TCP connections to an external broker like RabbitMQ, which handles durable subscriptions, clustering, and cross-node message fan-out.
The critical RabbitMQ STOMP configuration detail:
- RabbitMQ's STOMP plugin listens on port 61613, not the standard AMQP port 5672; pointing the relay at the wrong port causes a silent failure — the STOMP handshake cannot complete over an AMQP connection
- The only indication is a
BrokerAvailabilityEvent(available=false)buried in startup logs; clients can connect to the WebSocket endpoint but all messages are silently dropped
System and client connection types:
- The relay maintains two types: a system connection for heartbeats and management messages with elevated credentials, and client connections mapping to individual browser sessions
- Configure system heartbeats at 10-second intervals — the default is zero, meaning a dead broker connection goes undetected for minutes while messages disappear silently
The broker restart scenario:
- When the broker restarts and the relay reconnects, Spring re-establishes the system connection automatically but client subscriptions are lost; connected users stop receiving messages with no error in client or server logs
- The fix is client-side reconnection logic that re-subscribes to all active topics on STOMP reconnect — without this, a broker restart silently breaks all live sessions
I recommend listening for BrokerAvailabilityEvent and alerting when the broker stays unavailable for more than 30 seconds, and implementing client-side auto-reconnect with re-subscription from day one.
Spring WebSocket Message Broker Configuration — Full Broker Setup
Direct Answer
Replace enableSimpleBroker() with enableStompBrokerRelay() and point it at a running RabbitMQ or ActiveMQ instance. The relay forwards STOMP frames between the Spring app and the external broker, enabling durable queues, clustering, and cross-node pub/sub.
Common Mistakes & Pitfalls
Using enableSimpleBroker in production — it has no persistence, no clustering, and no durability.
Check your understanding
Answer these without looking back at the article.
- What is the difference between the system STOMP connection and client STOMP connections in the relay?
- How does enableStompBrokerRelay handle broker disconnections?
- How do you send messages to a specific user across multiple server nodes?
Related interview prep categories
1Want a guided curriculum order?
These modules are also sequenced in our flagship backend interview track — open it when you prefer an ordered path instead of browsing by topic.