Foundatio.Redis
Foundatio.Redis copied to clipboard
RedisMessageBus seems not reliable when subscriber is down
Hello,
When testing Publish/Subscribe with RedisMessageBus i've got some reliability issues.
If you kill down the Subscriber, and publish some messages with the client et then restart de Subscriber, messages are not processed.
Any idea on this? Thanks you in advance.
Best Regards. Yoann
After reading the code, the subscription is automaticaly Unsubsrcibed on Dispose.
public override void Dispose() {
base.Dispose();
if (_isSubscribed) {
using (_lock.Lock()) {
if (!_isSubscribed)
return;
bool isTraceLogLevelEnabled = _logger.IsEnabled(LogLevel.Trace);
if (isTraceLogLevelEnabled) _logger.LogTrace("Unsubscribing from topic {Topic}", _options.Topic);
_options.Subscriber.Unsubscribe(_options.Topic, OnMessage, CommandFlags.FireAndForget);
_isSubscribed = false;
if (isTraceLogLevelEnabled) _logger.LogTrace("Unsubscribed from topic {Topic}", _options.Topic);
}
}
}
It sould be great to have an option in RedisMessageBusOptions.cs to allow subscription persistence.
When you dispose of an instance it will unsubscribe the current instance. If you create a new message bus instance it will resubscribe. Message bus instances should be singletons (a single instance and long lived). If you have a scenario that's failing and not recovering, can you please create a unit test for us.
Actually, what i want is to keep published messages alive, even if previously subscribers are down. Then when subscribers restart, messages should be processed.
Using the sample in source code you can reproduce what i say.
- Start SampleJobClient
- Start SampleJob
- Publish messages with the client. Theses messages are processed by the SampleJob subscriber.
- Kill SampleJob
- Continue publishing messages with the client
- Restart SampleJob, pending messages are not processed : That's my problem.
I guess this sums up what's going on here: https://stackoverflow.com/questions/6192177/redis-pub-sub-with-reliability and https://www.redisgreen.net/blog/pubsub-intro/ We've always treated it as if no one is listening then why keep the messages and it's worked for our use cases where we don't care about delivery guarantees for most of our messaging. That's not to say we shouldn't. It might be worth while to look into using redis streams instead. Have you investigated this?