public void Subscribe <TDomainEvent>(string database, string channel, Action <TDomainEvent> handler) where TDomainEvent : IDomainEvent { if (string.IsNullOrWhiteSpace(channel)) { throw new ArgumentException("Channel not specified.", nameof(channel)); } if (handler == null) { throw new ArgumentNullException(nameof(handler)); } var subscriber = _connModule.GetSubscriber(database); subscriber.Subscribe(channel, (onChannel, message) => { var messageParts = ChannelMessageEncoder.UnPack(message); TDomainEvent domainEvent = _serializationMgr.Deserialize <TDomainEvent>( messageParts.contentType, messageParts.messageData); LogReceivedDomainEvent(database, channel, domainEvent); handler(domainEvent); }); }
// Returns a named instance of the service used to subscribe to // Redis messages published to the database. public ISubscriber GetSubscriber(string name) => _connModule.GetSubscriber(name);