예제 #1
0
 private void HandleEnd(TimeSpan duration, RabbitMqHandleParams prms)
 {
     if (RabbitMqLogger.IsEnabled(Constants.Events.ReceiveEnd))
     {
         RabbitMqLogger.Write(Constants.Events.ReceiveEnd, RabbitMqDurationEvent <RabbitMqHandleParams> .Success(duration, prms));
     }
 }
예제 #2
0
 private void HandleFail(Exception ex, TimeSpan duration, RabbitMqHandleParams prms)
 {
     if (RabbitMqLogger.IsEnabled(Constants.Events.ReceiveFail))
     {
         RabbitMqLogger.Write(Constants.Events.ReceiveFail, RabbitMqFailEvent <RabbitMqHandleParams> .Fail(ex, duration, prms));
     }
 }
예제 #3
0
 private void HandleStart(RabbitMqHandleParams prms)
 {
     if (RabbitMqLogger.IsEnabled(Constants.Events.ReceiveStart))
     {
         RabbitMqLogger.Write(Constants.Events.ReceiveStart, RabbitMqEvent <RabbitMqHandleParams> .Success(prms));
     }
 }
예제 #4
0
        public override Task HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, byte[] body)
        {
            var prms = new RabbitMqHandleParams
            {
                ConsumerTag = consumerTag,
                DeliveryTag = deliveryTag,
                Redelivered = redelivered,
                Exchange    = exchange,
                RoutingKey  = routingKey,
                Properties  = properties,
                Body        = body
            };

            Task.Run(async() =>
            {
                Stopwatch sw = null;
                try
                {
                    HandleStart(prms);
                    sw = Stopwatch.StartNew();
                    await base.HandleBasicDeliver(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body);
                    sw.Stop();
                    HandleEnd(sw.Elapsed, prms);
                }
                catch (Exception ex)
                {
                    if (sw == null)
                    {
                        return;
                    }

                    sw.Stop();
                    HandleFail(ex, sw.Elapsed, prms);
                }
            });
            return(Task.CompletedTask);
        }