Skip to content

Support for multiple external STOMP message brokers #22535

Open
@TLN2

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

  1. <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 of SimpMessagingTemplate to be used for this message broker.
  2. 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.

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: feedback-providedFeedback has been providedtype: enhancementA general enhancement

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions