Use SimpMessagingTemplate Without Creating Spring 4 Web Socket Message Broker

Can I send a message to a message broker using the SimpMessagingTemplate#convertAndSendToUser or SimpMessagingTemplate#convertAndSend without setting up website broker messages using @EnableWebSocketMessageBroker ?

What I'm trying to do is use one web server for messaging for two instances of the application server (one spring 4 and one spring 3). I created one web server with spring 4 enabled, spring loading and a websocket message firewall.

Now I want the two application servers to send messages to rabbitmq so that they send them to clients that are subscribed to it.

The first problem I encountered is the lack of configuration of brokerage messages for websites, SimpMessagingTemplate will not be automatically transmitted in the context of the application. I could not get him to inject without creating a bulletin board with websites.

Please help me find out if this is possible.

By the way, I have the previous question without an answer.

+7
spring spring-mvc spring-websocket spring-4
source share
1 answer

Well, after reading a lot of documentation, I found the answer myself. The main thing is that this architecture is as follows.

enter image description here

In this architecture, spring acts as a gateway for communication between the message broker and the client. spring does nothing (unless necessary), but redirects the request to the message broker (STOMP messages). The configuration stored on spring defines a couple of important things. One is sharing, and the other is with routing keys. The spring configuration gives us an abstract layer, so we subscribe and send messages to the message broker without fuss.

SimpMessagingTemplate is an abstract layer that we use to communicate with the message broker. spring creates a bean using data. I could not create an instance of SimpMessagingTemplate manually. I have to upgrade the spring 3 application to spring 4 in order to use the websites.

Since spring and the message broker are decoupled, clustering the application instance does not affect the message broker. spring only contacts a message broker when it needs to subscribe to a channel or when it needs to publish a message to a channel. So if there are two instances that subscribe to the same channel, there will be two queues connecting the same exchange using the same routing key. Messages published in the channel will be available to all subscribers (queues), because they all use the same routing key. See the rabbitmq plugin documentation for a more detailed description.

+1
source share

All Articles