private async Task TryRunHandler <TEvent>(IEventHandlerAsync <TEvent> handler, TEvent @event) { try { if (!await handler.ShouldHandleAsync(@event).ConfigureAwait(false)) { return; } await handler.HandleAsync(@event).ConfigureAwait(false); } catch (Exception exception) { await TryReportError(exception, handler, @event).ConfigureAwait(false); } }
public Task HandleAsync(TEvent @event) => _eventHandler.HandleAsync(@event);
public static ISubscription WithEventHandlerAsync <TEvent>(this IBusClient bus, IEventHandlerAsync <TEvent> handler, string exchangeName = null, string routingKey = null) where TEvent : IEvent => bus.SubscribeAsync <TEvent>(async(msg, context) => await handler.HandleAsync(msg), cfg => cfg.WithExchange(e => e.WithName(exchangeName)).WithRoutingKey(routingKey));