MessageBrokerRegistry is the Spring class you use to configure the message broker behind STOMP over WebSocket. You receive it in configureMessageBroker() of a WebSocketMessageBrokerConfigurer, and with it you choose the broker (in-memory simple broker or an external STOMP broker relay), the destination prefixes that route messages, and the prefix used for user-specific destinations.
Without a configured registry, clients can connect but messages have nowhere to be routed. The registry defines which destinations go to your @MessageMapping methods and which go to the broker for fan-out to subscribers.
Spring's messaging support splits traffic into three channels: the client inbound channel (messages from clients), the client outbound channel (messages to clients) and the broker channel (messages for the broker). MessageBrokerRegistry configures how the broker side of this works. You enable it with @EnableWebSocketMessageBroker and implement WebSocketMessageBrokerConfigurer:
registerStompEndpoints() defines where clients connect, while configureMessageBroker() defines how messages are routed after the connection exists. In Spring Boot 3 and Spring Framework 6 the WebSocket classes live in the jakarta.websocket namespace, but the Spring classes above keep the same package names.
The two settings you use most decide where a message goes:
| Setting | Purpose | Example |
|---|---|---|
setApplicationDestinationPrefixes("/app") | Messages whose destination starts with this prefix are routed to @MessageMapping methods | Client sends to /app/chat |
enableSimpleBroker("/topic", "/queue") | Messages sent to these destinations are handled by the broker and delivered to subscribers | Client subscribes to /topic/news |
setUserDestinationPrefix("/user") | Prefix for user-specific destinations (default is /user) | convertAndSendToUser() |
A controller connects the two sides:
A client sends to /app/chat, the application prefix strips the /app part and finds the /chat mapping, and the return value goes to the broker, which delivers it to everyone subscribed to /topic/messages. By convention /topic is used for publish-subscribe (one to many) and /queue for point-to-point messages, but the simple broker does not enforce this.
enableSimpleBroker() starts an in-memory broker inside your application. It is enough for development, tests and single-instance deployments. It does not share state between instances and supports only a subset of STOMP.
For production clusters, use enableStompBrokerRelay(), which forwards messages to a full-featured external STOMP broker such as RabbitMQ (with its STOMP plugin) or ActiveMQ:
The relay opens TCP connections to the broker on behalf of connected clients and keeps a separate system connection for messages sent from your application. Load credentials from configuration or a secret store rather than hard coding them as shown here. You can register only one of the simple broker or the relay at a time.
| Aspect | Simple broker | STOMP broker relay |
|---|---|---|
| Runs in | Your JVM | External broker |
| Clustering | No sharing between instances | Shared by all instances |
| STOMP features | Subset | Full broker support |
| Typical use | Development, small apps | Production at scale |
setUserDestinationPrefix("/user") changes the prefix that SimpMessagingTemplate.convertAndSendToUser() and @SendToUser resolve to per-session destinations.setPreservePublishOrder(true) guarantees that messages published to clients keep the order they were sent in, at some cost in throughput.setCacheLimit(int) limits the cache used to resolve destinations.enableSimpleBroker(...).setHeartbeatValue(new long[] {10000, 10000}) together with setTaskScheduler(...) enables STOMP heartbeats on the simple broker./topic/messages directly. This bypasses your controller; clients should send to the application prefix.app do not match destinations that start with /app.setAllowedOriginPatterns("*") on the endpoint in production. List your real origins.No. It is part of the STOMP messaging layer. Plain WebSocketHandler registrations use WebSocketConfigurer and have no broker.
enableSimpleBroker keeps subscriptions in memory inside your application, while enableStompBrokerRelay forwards to an external STOMP broker that can serve many application instances.
Yes, and you normally do. Application prefixes route to @MessageMapping methods, and broker prefixes route to subscribers.
Use SimpMessagingTemplate.convertAndSendToUser(username, "/queue/reply", payload). Clients subscribe to /user/queue/reply, and Spring resolves the session of that user.
MessageBrokerRegistry is the configuration entry point for the message broker in Spring WebSocket and STOMP applications. Use setApplicationDestinationPrefixes() to route client messages to controllers, enableSimpleBroker() for in-memory pub-sub on a single node, and enableStompBrokerRelay() when you need an external broker and several application instances.