【发布时间】:2016-01-13 11:37:16
【问题描述】:
我正在尝试将 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 消息代理代理之间的关系是什么?
【问题讨论】:
标签: java spring spring-integration spring-websocket