private async void RouteEvent(object sender, MqMessage message)
        {
            if (!routing.ContainsKey(message.Type))
            {
                return;
            }

            var method  = routing[message.Type];
            var data    = Parse(message.Type, message.Data);
            var context = new MessageContext {
                FlowId = message.FlowId, Type = message.Type, ReplyTo = message.ReplyTo
            };

            logger.LogInformation($"Service='{serviceName}' FlowId='{message.FlowId}' Method='{message.Type}' Type='Start'");
            var stopwatch = Stopwatch.StartNew();

            try
            {
                await((Task)method.Invoke(service, new[] { context, data }));
            }
            catch (Exception e)
            {
                if (message.ReplyTo != null)
                {
                    this.publishingRouter.Publish(message.ReplyTo, new ErrorEvent {
                        Error = e.GetType().Name, Message = e.Message
                    }, message.FlowId);
                }
                logger.LogInformation($"Service='{serviceName}' FlowId='{message.FlowId}' Method='{message.Type}' Type='Error'");
            }
            finally
            {
                logger.LogInformation($"Service='{serviceName}' FlowId='{message.FlowId}' Method='{message.Type}' Type='End' Processing='{stopwatch.ElapsedMilliseconds}'");
            }
        }
 private void MessageHandler(object sender, MqMessage message)
 {
     if (message.FlowId != null)
     {
         this.Callbacks.TryRemove(message.FlowId, out var callback);
         callback?.Invoke(message);
     }
 }
 private void Handle <T>(TaskCompletionSource <T> tcs, MqMessage message)
 {
     if (message.Type == typeof(ErrorEvent).Name)
     {
         var data = JSON.Deserialize <ErrorEvent>(message.Data, Options.ISO8601Utc);
         logger.LogInformation($"Service='{serviceName}' FlowId='{message.FlowId}' Method='{message.Type}' Type='Error'");
         tcs.SetException(new Exception(data.Message));
     }
     else
     {
         var data = JSON.Deserialize <T>(message.Data, Options.ISO8601Utc);
         tcs.SetResult(data);
     }
 }