Using RabbitMQ stomp adapter to relay message across subscriptions in different servers

你离开我真会死。 提交于 2019-12-24 00:48:48

问题


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("*");
}

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

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

messagingTemplate.convertAndSend(destination, message);

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?


回答1:


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")

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!




回答2:


I'm not sure if this is exactly the same thing but I just solved a very similar problem. I posted my answer here: Sending STOMP messages from other layers of an application

I decided to split the implementation of the relay server into it's own setup and then manually forward messages between the rabbitmq server and the websocket subscribers on each of the servers.

Hopefully this can be of some use for you.



来源:https://stackoverflow.com/questions/41904819/using-rabbitmq-stomp-adapter-to-relay-message-across-subscriptions-in-different

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!