使用 RabbitMQ stomp 适配器在不同服务器的订阅之间中继消息 [英] Using RabbitMQ stomp adapter to relay message across subscriptions in different servers

查看:74
本文介绍了使用 RabbitMQ stomp 适配器在不同服务器的订阅之间中继消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Spring 设置 Stomp 服务器端点(扩展 AbstractWebSocketMessageBrokerConfigurer)

I am using Spring to setup Stomp server endpoints (extending AbstractWebSocketMessageBrokerConfigurer)

@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableStompBrokerRelay("/topic","/queue")
        .setRelayHost(<rmqhost>);
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint("/myapp/websockets").setAllowedOrigins("*");
}

目标是我可以有多个服务器,并且客户端将针对特定主题连接到其中任何一个:/topic/topic-id-1

The objective is that I can have multiple servers, and a client will connect to any one of them for a specific topic: /topic/topic-id-1

任何服务器(一次)都可以使用 Spring 的 SimpMessagingTemplate 为该主题发送消息

Any of the server (at a time) can send a message for this topic using Spring's SimpMessagingTemplate

messagingTemplate.convertAndSend(destination, message);

目的地 = "/topic/topic-id-1".例如:我有 2 个服务器节点和一个客户端连接到每个节点,订阅相同的主题 (/topic/topic-id-1).目标是,如果服务器 1 为 topic-id-1 发送消息,它应该通过 rabbitmq 中继到订阅同一主题的两个客户端.我看到一个队列被创建,路由键为topic-id-1",但只有连接到服务器的客户端发送消息显式接收它.我在这里错过了什么吗?难道 RMQ stomp 代理不应该在同一主题的所有订阅中中继由一台服务器发送的订阅消息吗?服务器是否需要做其他事情来获取其他节点发送的消息?

where destination = "/topic/topic-id-1". For ex: I have 2 server nodes and a client connecting to each one of them, subscribing to the same topic (/topic/topic-id-1). The objective is that if server 1 sends a message for topic-id-1, it should relay via rabbitmq to both clients subscribing to the same topic. I see a queue being created with routing key as "topic-id-1", but only the client connecting to the server sending out the message explicitly receives it. Am I missing something here? Isn't RMQ stomp broker supposed to relay the message send by one server for a subscription, across all the subscriptions for the same topic? Does the server need to do something else to get messages sent by other node?

推荐答案

我遇到了同样的问题.经过一整天的探索,我终于找到了解决方案!!不过配置起来很容易.

I met the same problem. After a whole day explored, I found the solution finally!! It's easy to configure though.

registry.enableStompBrokerRelay("/topic/", "/queue/", "/exchange/") 
   .setUserDestinationBroadcast("/topic/log-unresolved-user") 
   .setUserRegistryBroadcast("/topic/log-user-registry")

您唯一需要做的就是在启用 StompBrokerRelay 时配置 setUserDestinationBroadcastsetUserRegistryBroadcast.它有效!

The only thing you need to do is configure setUserDestinationBroadcast and setUserRegistryBroadcast when you enable the StompBrokerRelay. And it works!

我从此处找到了解决方案.认为那个人!

I found the solution from here. Thinks that guy!

这篇关于使用 RabbitMQ stomp 适配器在不同服务器的订阅之间中继消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆