Search code examples
springcluster-computingspring-websocket

How to configure Spring WebSocket in cluster


I have configured Spring Websocket over Stomp in my project.

My enviroment have 2 cluster node and one balancer. How can configure the spring websocket in cluster mode?

Thanks in advance


Solution

  • You need to use message broker like ActiveMQ / RabbitMQ etc. Either you can set a seperate node for message broker or you can also set it on any node in your 2 cluster node.

    Next thing you need to configure enableStompBrokerRelay in your WebSocketConfig on both nodes.

      @Override
      public void configureMessageBroker(MessageBrokerRegistry config) {
        config.setApplicationDestinationPrefixes("/app");
        config.enableStompBrokerRelay("/topic","/queue").setRelayHost("MQHOSTNAME").setRelayPort(MQPORT);
      }