-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Track channel and pattern subscriptions to avoid unintended unsubscribe in ReactiveRedisMessageListenerContainer
#2386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The issue here is that each subscription creates a Redis subscription that is unsubscribed when cancelling the stream:
In contrast to To achieve a similar usage pattern you would need to share subscriptions within your controller and store processors that handle multiplexing in a e.g. It would be possible to rewrite |
Thanks for the quick feedback Mark.
Hmm, but doesn't that mean that number of subscribers as returned by
I suspected something like that, but then Lines 62 to 64 in eaef5da
|
The number of subscribers is computed from all subscribers. Typically you would have a count > 1 when using multiple connections.
is meant to subscribe to multiple channels/patterns using a single connection, not that you can subscribe to the same channel multiple times. We should improve our documentation wording to clarify that aspect. |
We revisited this topic. Reactive messaging is associated with demand/back pressure, and we don't want to create a place where we cause congestion or growing queues because of shared subscriptions. We can (and should do) add protection against unintended un-subscriptions. That is, if you have two subscribers to the same channel and one performs an unsubscribe, the other will also unsubscribe. |
ReactiveRedisMessageListenerContainer
This is something I noticed shortly after opening #2229 but failed to report it back then.
On a project I worked at that time, we wanted to reduce the number of Redis topic subscriptions by employing channel multiplexing in a way like imperative
RedisMessageListenerContainer
is typically used. However, our attempt to useReactiveRedisMessageListenerContainer
in similar fashion failed due to an issue/limitation I'll try to describe here.We created
ReactiveRedisMessageListenerContainer
bean and used it to create message streams that would be exposed over HTTP endpoints, and noticed that when multiple clients subscribe to the same topic, the stream breaks (or better said stalls) for all subscribers the moment first client cancels their connection (and thus the apparently underlying stream as well). When some client connects again, the stream continues working for all the clients that kept their connection open.The issue can be reproduced using
sample-webflux
project fromwebflux-channel-multiplexing
branch in this repo. After starting the sample, follow the instructions from project's readme to subscribe multiple clients and then unsubscribe some.I acknowledge that this might be an issue with how we used
ReactiveRedisMessageListenerContainer
(as none of use were reactive experts), but to us it appeared that message streams returned byReactiveRedisMessageListenerContainer
should be shareable in order to achieve a true channel multiplexing capability.The text was updated successfully, but these errors were encountered: