public async Task PublishToBus(IEvent @event) { await _service.SaveEventAsync(@event); try { _bus.Publish(@event); await _service.MarkEventAsPublishedAsync(@event); } catch (Exception) { await _service.MarkEventAsFailedAsync(@event); throw; } }
public async Task PublishToBus <T>(T @event, string exchange, CancellationToken token) where T : IEvent { await _service.SaveEventAsync(@event); try { await Task.WhenAll(_publishers.Select(p => p.Publish(@event, exchange, token))); await _service.MarkEventAsPublishedAsync(@event); } catch (Exception) { await _service.MarkEventAsFailedAsync(@event); throw; } }