Пример #1
0
        private async Task ProcessAsync(IncomingMessage msg, CancellationToken cToken)
        {
            IMessageHandler handler = null;

            try
            {
                handler = _handlerFactory.Create(msg);
                Logger.Debug("Handler {0} found for request {1}", handler.GetType().Name, msg.GetType().Name);
                var responses = await handler.HandleAsync(msg, cToken);

                if (responses == null)
                {
                    return;
                }

                Logger.Debug("{0} messages to send back", responses.Count);
                foreach (var r in responses)
                {
                    await _nodeMessageChannel.SendAsync(r, cToken);

                    MessageLog.Debug("OUT:{0}", r);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
            finally
            {
                if (handler != null)
                {
                    _handlerFactory.Release(handler);
                }
            }
        }