async Task IFilter <ConsumeContext <TMessage> > .Send(ConsumeContext <TMessage> context, IPipe <ConsumeContext <TMessage> > next) { Stopwatch timer = Stopwatch.StartNew(); try { await _consumerFactory.Send(context, _consumerPipe); await context.NotifyConsumed(timer.Elapsed, TypeMetadataCache <TConsumer> .ShortName); await next.Send(context); } catch (Exception ex) { await context.NotifyFaulted(timer.Elapsed, TypeMetadataCache <TConsumer> .ShortName, ex); throw; } }
async Task IConsumerFactory <TConsumer> .Send <T>(ConsumeContext <T> context, IPipe <ConsumerConsumeContext <TConsumer, T> > next) { DateTime timestamp = DateTime.UtcNow; Stopwatch timer = Stopwatch.StartNew(); try { await _consumerFactory.Send(context, next); timer.Stop(); context.NotifyResourceUsageCompleted(context.ReceiveContext.InputAddress, timestamp, timer.Elapsed); } catch (Exception ex) { context.NotifyResourceUsageFailed(context.ReceiveContext.InputAddress, timestamp, timer.Elapsed, ex); throw; } }
async Task IFilter <ConsumeContext <TMessage> > .Send(ConsumeContext <TMessage> context, IPipe <ConsumeContext <TMessage> > next) { var activity = LogContext.IfEnabled(OperationName.Consumer.Consume)?.StartActivity(new { ConsumerType = TypeMetadataCache <TConsumer> .ShortName, MessageType = TypeMetadataCache <TMessage> .ShortName }); var timer = Stopwatch.StartNew(); try { await Task.Yield(); await _consumerFactory.Send(context, _consumerPipe).ConfigureAwait(false); await context.NotifyConsumed(timer.Elapsed, TypeMetadataCache <TConsumer> .ShortName).ConfigureAwait(false); await next.Send(context).ConfigureAwait(false); } catch (OperationCanceledException exception) { await context.NotifyFaulted(timer.Elapsed, TypeMetadataCache <TConsumer> .ShortName, exception).ConfigureAwait(false); if (exception.CancellationToken == context.CancellationToken) { throw; } throw new ConsumerCanceledException($"The operation was cancelled by the consumer: {TypeMetadataCache<TConsumer>.ShortName}"); } catch (Exception ex) { await context.NotifyFaulted(timer.Elapsed, TypeMetadataCache <TConsumer> .ShortName, ex).ConfigureAwait(false); throw; } finally { activity?.Stop(); } }
public Task Send <TMessage>(ConsumeContext <TMessage> context, IPipe <ConsumerConsumeContext <TConsumer, TMessage> > next) where TMessage : class { return(_delegate.Send(context, next)); }
Task IConsumerFactory <TConsumer> .Send <T>(ConsumeContext <T> context, IPipe <ConsumerConsumeContext <TConsumer, T> > next) { return(_factory.Send(context, next)); }