Пример #1
0
        public void Dispatch(MessageInfo info, object message)
        {
            var messageData = (TEvent)message;

            _logger?.Info($"Event: EventHandlerDispatcher validate message is started; MessageId:{info.Id}");
            _contractValidatorService.Validate(messageData);
            _logger?.Info($"Event: EventHandlerDispatcher validate message is finished; MessageId:{info.Id}");

            _logger?.Info($"Event: EventHandlerDispatcher handle message is started; MessageId:{info.Id}");
            if (info.MessageType?.BatchSize != null && info.MessageType?.BatchSize != 0)
            {
                var batchingHandler = _serviceProvider.GetService <IBatchingHandler <TEvent> >();
                if (batchingHandler != null)
                {
                    batchingHandler.Handle(info, messageData);
                }
                else
                {
                    _eventHandler.Handle(messageData);
                }
            }
            else
            {
                _eventHandler.Handle(messageData);
            }
            _logger?.Info($"Event: EventHandlerDispatcher handle message is finished; MessageId:{info.Id}");
        }
Пример #2
0
        private void ValidateContract <T>(T message)
        {
            if (!typeof(T).IsInterface)
            {
                throw new InvalidOperationException("Only interfaces are allowed as a generic parameters");
            }

            _contractValidatorService.Validate <T>((T)message);
            if (message == null)
            {
                throw new InvalidDataException("Event message can't be null");
            }
        }
Пример #3
0
 public void Handle(T command)
 {
     _contractValidatorService.Validate <T>(command);
     _eventHandler.Handle(command);
 }
Пример #4
0
 public void Dispatch(MessageInfo info, object message)
 {
     _contractValidatorService.Validate <TCommand>((TCommand)message);
     _commandHandler.Handle((TCommand)message);
 }