我有这些 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();
}
}
我天真地认为Spring使用我的当前ActiveMQ配置,但实际上它尝试连接到位于本地主机上的默认STOMP端口的服务器。我发现可以通过输入以下内容来更改此配置:
Naively, I though spring used 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);
好的,但是目前我有一个故障转移设置,其中有两个代理 (共享文件系统的主/备)。如何为stomp代理中继配置这样的设置?
如果不可能,我考虑以下解决方案:
- 使用简单的(内存)代理,这并不推荐
- ActiveMQ用于多个操作(不限于WebSockets),我不知道将stomp/WebSockets队列与其他功能队列混合使用是否推荐。考虑到这一点,我可以创建另一个 ActiveMQ 实例 (也许使用VM传输方式).
第二个选项可行吗?