rstoyanchev / spring-websocket-portfolio

736 stars 443 forks source link

How to use a custom SubscriptionRegistry? #78

Closed cmhteixeira closed 4 years ago

cmhteixeira commented 4 years ago

Is it necessary to fork AbstractMessageBrokerConfiguration to implement our own custom SubscriptionRegistry, or is there a less intrusive alternative ?

I am in a situation where I need to have a more personalised SubscriptionRegistry. In particular, I need for the rest of my application to know when a user subscribes to a certain destination. Currently, I am using the ApplicationContext events (e.g SessionSubscribeEvent, SessionUnsubscribeEvent, ...) to inform me of that. This has grown into a scenario in which I am basically managing subscriptions for sessions in parallel with the DefaultSubscriptionRegistry. This could be overcome if only I could make a rather contained change to the DefaultSubscriptionRegistry [inject an observable there].

Sofar, I am have not been able to do that. I believe my problem is that method getBrokerRegistry() on class AbstractMessageBrokerConfiguration is final. If it weren't, I reckon I could overwrite it to return a custom MessageBrokerRegistry. This custom MessageBrokerRegistry would just overwrite method enableSimpleBroker. Eventually, I would be able to get hold of the SimpleBrokerMessageHandler and call its method public setSubscriptionRegistry(SubscriptionRegistry myCustomSubscriptionRegistry).

I am contemplating simply forking AbstractMessageBrokerConfiguration, copying all its content , but removing the final keyword. Is there any better way to achieve this?

Relevant similar issues : /spring-projects/spring-framework#16645, #36

rstoyanchev commented 4 years ago

Thanks for getting in touch but this question doesn't belong here. Please use StackOverflow and If you believe there is an issue or something missing please report it in https://github.com/spring-projects/spring-framework/issues.

It's not clear why you can't extend DelegatingWebSocketMessageBrokerConfiguration and override simpleBrokerMessageHandler(), and of course also remove @EnableWebSocketMessageBroker and declare your own DelegatingWebSocketMessageBrokerConfiguration as a bean.