我試圖在分佈式微服務中使用Spring WebSocketMessageBroker
的RabbitMq。使用RabbitMQ和分佈式微服務配置Spring WebSocketMessageBroker
我工作的設置是
內WebSocketMessageBroker,我使用下面的配置,從文檔採取:
@Configuration
@EnableWebSocketMessageBroker
public class WebsocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/push").setAllowedOrigins("*").withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableStompBrokerRelay("/queue/", "/topic/", "/app");
registry.setApplicationDestinationPrefixes("/app");
registry.setPathMatcher(new AntPathMatcher("."));
}
}
鑑於此配置,有什麼交換/隊列應該MyMicroservice
發佈到爲了消息被代理到Stomp服務?
我試過以下(在發佈端 - 內MyMicroservice)
@Configuration
@SpringBootApplication
@EnableRabbit
public class Config {
public static final String WEB_QUEUE = "/topic/myNotificationTopic";
public static final String WEB_EXCHANGE = "web.exchange";
@Bean
Queue webQueue() {
return new Queue(WEB_QUEUE, false);
}
@Bean
TopicExchange webExchange() {
return new TopicExchange(WEB_EXCHANGE);
}
@Bean
Binding binding(Queue webQueue, TopicExchange webExchange) {
return BindingBuilder.bind(webQueue).to(webExchange).with(WEB_QUEUE);
}
}
@Component
public class ExamplePublisher {
@Autowired
private AmqpTemplate amqpTemplate;
public void sendMessage() {
amqpTemplate.convertAndSend(Config.WEB_QUEUE, "Hello, world");
}
}
然而,該消息似乎並沒有被代理通過WebSocket連接。
需要明確的是,我的問題是:是否支持
- 這種類型的分佈式的配置外的開箱?
- 考慮到配置示例,服務可以發佈到的RabbitMq主題和Stomp messagebroker代理之間的關係是什麼?