StackExchange.Redis icon indicating copy to clipboard operation
StackExchange.Redis copied to clipboard

Why doesn't ISubscriber interface provide Unsubscribe for a specific ChannelMessageQueue

Open Nevak opened this issue 6 years ago • 2 comments

Hello everyone,

I'm working on an app that involves notifying users when friends come online / offline. I'm using PUB/SUB for this to communicate between different instances of our servers that the users connect to.

I have some confusion on how the Unsbuscribe is supposed to be used in the case of using ChannelMessageQueue. For example if we do:

var queue = m_connection.GetSubscriber().Subscribe(channelName); queue.OnMessage((msg) => { action(playerId, (PlayerPresenceState)(int)msg.Message); });

How should we unsbuscribe now? What I intuitively would do is something like:

m_connection.GetSubscriber().Unsubscribe(channelName, queue);

However the ISubscriber interface doesn't provide a method to unsubscribe by passing a queue. See something like:

void Unsubscribe(RedisChannel channel, ChannelMessageQueue queue = null, CommandFlags flags = CommandFlags.None);

Which seems odd, since the functionality in the RedisSubscriber is indeed there and implemented and working (apparently). It's just never used.

See: https://github.com/StackExchange/StackExchange.Redis/blob/8590f20b7d39e05e52efd3e41b14f30443daa924/src/StackExchange.Redis/RedisSubscriber.cs#L532 and https://github.com/StackExchange/StackExchange.Redis/blob/8590f20b7d39e05e52efd3e41b14f30443daa924/src/StackExchange.Redis/RedisSubscriber.cs#L215

Does anyone know why? Or how do you handle unsubscriptions?

Thanks!

Nevak avatar Nov 22 '20 10:11 Nevak

The ChannelMessageQueue instance (returned from the subscribe methods) has unsubscribe APIs as instance methods. Just... call them?

mgravell avatar Nov 22 '20 17:11 mgravell

You are absolutely right. Sorry, I had completely overlooked it. Thank you!

Nevak avatar Nov 23 '20 00:11 Nevak