This library is written in .NET standard and provides reliability to delivering messages via Redis. By design Redis pub/sub message delivery is not reliable so it can happen that some messages can get lost due to network issues or they can be delivered more than once in case of Redis replication failure.
This library adds a lightweight infrastructure to handle such error scenarios.
// initialization
var multiplexer = ConnectionMultiplexer.Connect("connection options");
// subscribe to a reliable channel
var channelIntegrityCheck = multiplexer.GetSubscriber()
.Reliably()
.Subscribe(
channel: "channel-name",
onExpectedMessage: (channel, message) => Trace.TraceInformation($"Message with ID={message.Id} was received as expected. Message content='{message.Content}'"),
onMissedMessage:,
onDuplicatedMessage:,
onMissingMessages:);
// publish to a reliable channel
multiplexer.GetSubscriber()
.Reliably()
.Publish(
channel: "channel-name",
message: "message-content",
messageExpiration: TimeSpan.FromMinutes(10));
// channel integrity check - optional
// useful when delivering messages is not as frequent. In such a case
// we can ensure manually that reliable subscriber is still able to receive messages.
// Example:
// if last processed message was earlier than 1sec ago
// i.e. we did not receive messages within the last second
if (channelIntegrityCheck.LastActivityAt < DateTime.UtcNow.AddSeconds(-1))
{
// force reliable channel to get not processed messages
// from Redis server if there are some
channelIntegrityCheck.CheckForMissedMessages();
}
TODO
- Subscribing to channel patterns is not supported