Reputation: 961
I have this configuration for Spring and a full feature stomp broker (ActiveMQ):
@Configuration
@EnableWebSocketMessageBroker
public class WebsocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
private static Logger LOG = org.slf4j.LoggerFactory.getLogger(WebsocketConfig.class);
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableStompBrokerRelay("/topic/", "/queue/");
config.setApplicationDestinationPrefixes("/app");
config.setUserDestinationPrefix("/user");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/socket").withSockJS();
}
}
I thought Spring would use my current ActiveMQ configuration, but in reality it tries to connect into a server located in localhost
with a default stomp port. I discovered that is possible to change this configuration by typing:
config.enableStompBrokerRelay("/topic/", "/queue/")
.setRelayHost("activeMQHOST")
.setRelayPort(9999);
Thats fine, but currently I have a failover setup with two brokers. How can I configure such setup for the stomp broker relay?
If not possible, I thought in the following solutions:
The second option is advisable?
Upvotes: 18
Views: 1420
Reputation: 435
Here's an example configuration for a failover setup with two brokers:
@Configuration
@EnableWebSocketMessageBroker
public class WebsocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
private static Logger LOG = org.slf4j.LoggerFactory.getLogger(WebsocketConfig.class);
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
StompBrokerRelayRegistration relayRegistration = config.enableStompBrokerRelay("/topic/", "/queue/");
relayRegistration.setRelayHost("tcp://activeMQHOST1:61616,tcp://activeMQHOST2:61616");
relayRegistration.setClientLogin("USERNAME");
relayRegistration.setClientPasscode("PASSWORD");
relayRegistration.setSystemLogin("USERNAME");
relayRegistration.setSystemPasscode("PASSWORD");
config.setApplicationDestinationPrefixes("/app");
config.setUserDestinationPrefix("/user");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/socket").withSockJS();
}
}
Here you can use setRelayHost method takes a comma-separated list of the two broker's addresses, and the setClientLogin, setClientPasscode, setSystemLogin, and setSystemPasscode methods specify the login credentials for the clients and the system.
Upvotes: 1