Exemple #1
0
        public void MessageHandler(IMessage message, IServiceProvider serviceProvider)
        {
            var logContext = $"{nameof(MessageHandler)} on {_dispatcherContext}, MessageId={message.Id}";

            _logger.LogDebug($"+{logContext}");
            string aggregateType = message.GetRequiredHeader(EventMessageHeaders.AggregateType);

            DomainEventHandler handler = _domainEventHandlers.FindTargetMethod(message, _eventTypeNamingStrategy);

            if (handler == null)
            {
                _logger.LogDebug($"{logContext}: No handler found for type='{aggregateType}'");
                return;
            }

            var param = (IDomainEvent)JsonMapper.FromJson(message.Payload, handler.EventType);

            Type envelopeType = typeof(DomainEventEnvelope <>).MakeGenericType(handler.EventType);
            var  envelope     = (IDomainEventEnvelope <IDomainEvent>)Activator.CreateInstance(envelopeType,
                                                                                              message,
                                                                                              aggregateType,
                                                                                              message.GetRequiredHeader(EventMessageHeaders.AggregateId),
                                                                                              message.GetRequiredHeader(MessageHeaders.Id),
                                                                                              param);

            handler.Invoke(envelope, serviceProvider);
            _logger.LogDebug($"-{logContext}: Processed message of type='{aggregateType}'");
        }
Exemple #2
0
 private IMessage ToMessage(ConsumeResult <string, string> record)
 {
     return(JsonMapper.FromJson <Message>(record.Value));
 }