Description
The problem
<websocket:message-broker>
effectively supports only one instance per application, which is a painful limitation in some projects. It would be much better if you could encapsulate different business concerns into separate endpoints with different sets of prefixes and other rules.
I debugged into the issue, trying to find out what could be done and realized that there was not much at the moment.
Specifically, org.springframework.web.socket.config.MessageBrokerBeanDefinitionParser
has constants for the names for all beans it is registering, including an instance of SimpMessagingTemplate
under the name "brokerMessagingTemplate"
. This is even mentioned in the official documentation:
The bean name is
"brokerMessagingTemplate"
if required for qualification with@Qualifier.
"
This design has its benefits because obviously MessageBrokerBeanDefinitionParser
registers quite a couple of beans with some complex wiring. Hiding this complexity is a good thing in general. However, if you look more closely you must admit that this approach totally defeats the idea of IoC because there's nothing you can configure and tweak anymore. Everything is hard-wired, just like direct construction.
I'm sure there would be a better solution.
My current suggestion/vision
<websocket:message-broker>
gets an optional argument named something like "broker-messaging-template" by which one can reference any own bean that is an instance ofSimpMessagingTemplate
to be used for this message broker.- There's another (yet to be implemented) bean definition parser that is able to create these beans, something like
<websocket:simp-message-template id="abc">
. If no other arguments are given, this creates the default wiring under the name/qualifier "abc". However you should be able to adjust everything (converters, channels, scheduler) if needed.