Ejemplo n.º 1
0
        private void HandleMessage(HandlerStore handlerStore, IDomainMessage domainMessage, int maxHandlers = int.MaxValue)
        {
            DomainResult domainResult;

            try
            {
                var targetHandlers = maxHandlers == int.MaxValue
                    ? handlerStore.Handlers
                    : handlerStore.Handlers.Take(maxHandlers);
                _logger.InfoFormat("Got {0} handlers to invoke", targetHandlers.Count());
                Parallel.ForEach(targetHandlers, handler => { handler.AsDynamic().Handle(domainMessage); });
                domainResult = new DomainResult(domainMessage, ResultCode.OK, string.Empty);
            }
            catch (Exception e)
            {
                _logger.Error("Error processing " + domainMessage.GetType(), e);
                var errorMessage = e.InnerException != null ? e.InnerException.Message : e.Message;
                _logger.Error("Error message " + errorMessage);
                domainResult = new DomainResult(domainMessage, ResultCode.Failed, errorMessage);
            }
            _resultPublisher.Publish(domainResult);
        }
Ejemplo n.º 2
0
        public string Call(IDomainMessage message)
        {
            var messageBody = JsonConvert.SerializeObject(message);

            return(Call(messageBody, message.GetType().Name));
        }