コード例 #1
0
        public override async Task PublishMessageAsync(IMessage message, CancellationToken cancellationToken)
        {
            if (message is IDomainEvent domainEvent && _pubModule.HasChannel(message.GetType()))
            {
                ChannelMeta channel  = _pubModule.GetChannel(domainEvent.GetType());
                IDatabase   database = _connModule.GetDatabase(channel.DatabaseName);

                // Only publish the domain-event if it passes the predicate associated
                // with the channel:
                if (!channel.Applies(domainEvent))
                {
                    return;
                }

                byte[] messageValue = _serialization.Serialize(domainEvent, channel.ContentType);

                // Build the name of the channel to publish to by combining the static channel
                // name with the optional event state data.
                string eventStateData = channel.GetEventStateData(domainEvent);
                string channelName    = $"{channel.ChannelName}.{eventStateData}";

                LogChannelPublish(domainEvent, channel.DatabaseName, channelName);
                byte[] messageData = ChannelMessageEncoder.Pack(channel.ContentType, messageValue);

                await database.PublishAsync(channelName, messageData).ConfigureAwait(false);
            }
        }
コード例 #2
0
        protected ChannelMeta <TDomainEvent> AddChannel <TDomainEvent>(string databaseName, string channel)
            where TDomainEvent : IDomainEvent
        {
            var meta = new ChannelMeta <TDomainEvent>(databaseName, channel);

            _channels.Add(meta);
            return(meta);
        }