Video in progress

In prod, the connection between the STOMP broker relay and RabbitMQ is lost. What does the Spring app do, what do users see, and how do you prepare the system for this?

The Spring "system" connection tries to reconnect, BrokerAvailabilityEvent is published, and while the broker is unavailable client frames are rejected; clients may get an ERROR and be disconnected. Preparation: a broker cluster, a degraded mode, and limiting the blast radius when one component goes down.

📖 Answer

The relay opens two kinds of connection: one "system" connection (for sending from inside the server) and a separate one for each client session. When RabbitMQ goes down:

  • the system connection drops, Spring tries to reconnect it automatically and publishes BrokerAvailabilityEvent(false);
  • SimpMessagingTemplate.convertAndSend throws an error or the message is lost because there's no broker; that depends on how your code handles the error;
  • the broker connections of the client sessions drop too, the clients get an ERROR frame, and their WebSockets are closed.

The result: all users disconnect at once and try to reconnect. When the broker comes back, a reconnect storm hits RabbitMQ itself too.

Preparation:

A broker cluster. Quorum queues and 3 nodes on RabbitMQ. Connect the relay not to a single host but to several addresses through a load balancer or setTcpClient.

Knowing the state. Listen to BrokerAvailabilityEvent and tie it to a health indicator. If the broker is down, readiness is false and new connections go to healthy instances, but if all instances point at the same broker, this doesn't help.

Degraded mode. Important events are still written to the outbox/inbox, and only the push stops. The client shows a "real-time is temporarily unavailable" state and switches to polling. For the user this is a slowdown, not an outage.

Blast radius. If one broker serves all features, one problem switches everything off. Separate broker clusters per feature (chat, notifications) or per user shard shrink the blast radius.

In a postmortem I usually come back to one question: why did a real-time layer outage stop the core business flow? If placing an order goes through WebSocket, that's an architecture mistake. Write operations should go through REST, and real-time should be only for notification.