Spring Websocket与Stomp全功能代理和故障转移

Rap*_*ale 9 spring activemq-classic stomp websocket spring-websocket

我有spring的配置和一个完整的功能stomp代理(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();
    }
}
Run Code Online (Sandbox Code Playgroud)

天真地,我虽然spring使用了我当前的activemq配置,但实际上它尝试使用默认的stomp端口连接到localhost中的服务器.我发现可以通过输入以下内容来更改此配置:

config.enableStompBrokerRelay("/topic/", "/queue/")
            .setRelayHost("activeMQHOST")
            .setRelayPort(9999);
Run Code Online (Sandbox Code Playgroud)

多数民众赞成,但目前我有两个经纪人的故障转移设置(master/flave with shared file system).如何为stomp broker relay配置这样的设置?

如果不可能,我想在以下解决方案中:

  1. 使用简单(内存中)代理,这是不可取的
  2. ActiveMQ用于多个操作(不限于websockets),我不知道是否建议将stomp/websockets队列与其他功能的队列混合使用.考虑一下,我可以创建另一个 activeMQ实例(可能使用VM传输.

第二种选择是可取的吗?

luc*_*fer 0

以下是具有两个代理的故障转移设置的示例配置:

@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();
    }
}
Run Code Online (Sandbox Code Playgroud)

在这里,您可以使用 setRelayHost 方法获取两个代理地址的逗号分隔列表,并使用 setClientLogin、setClientPasscode、setSystemLogin 和 setSystemPasscode 方法指定客户端和系统的登录凭据。