'Is there a concept of reverse controller for WebSockets?

I am implementing a WebSocket server in a small microservice and I wonder if conceptually there is a things such as a Reverse Controller?

I am using Spring Web Socket and the implementation defines that you can use a SimpMessagingTemplate to push anything to the Message broker. However it sounds messy that people can just inject a SimpMessagingTemplate and push data from everywhere in the code.

So to create some order I am thinking on defining some "Reverse Controllers" where all I have are calls to push data to a broker. I hope this will bring well defined points for the data going out. As always, anything that you think is an original thought most likely is not, so I wonder if there are any already defined patterns to manage this case.



Solution 1:[1]

Ok I think I found the anwer. In the Spring Data documentation WebSocket outgoing messages to a broker are defined inside normal @Controller or @RestController annotated clases.

So methods annotated with @SendTo or @SendToUser, or with lines like: this.simpMessagingTemplate.convertAndSend("/topic/mytopica", data);

are defined inside those clases. So it seems there is no concept of reverse Controller for outgoing messages to a broker, just use Controllers.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1