/// <summary> /// /// </summary> /// <param name="event"></param> /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param> /// <returns></returns> public Task Publish(DomainEvent @event, CancellationToken cancellationToken) { return(_executeMiddlewaresService.ExecuteAsync(@event, cancellationToken, (req, _) => { try { var serializedDomainEvent = _domainEventJsonSerializer.Serialize(req); var channel = _config.Channel(); channel.ExchangeDeclare(_rabbitMqParams.Value.ExchangeName, ExchangeType.Topic); var body = Encoding.UTF8.GetBytes(serializedDomainEvent); var properties = channel.CreateBasicProperties(); properties.Headers = new Dictionary <string, object> { { HeaderReDelivery, 0 } }; channel.BasicPublish(_rabbitMqParams.Value.ExchangeName, req.GetEventName(), properties, body); } catch (RabbitMQClientException) { //await _failOverPublisher.Publish(new List<DomainEvent> {domainEvent}, cancellationToken); } return Task.CompletedTask; })); }
/// <summary> /// /// </summary> /// <param name="event"></param> /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param> /// <returns></returns> public Task Publish(DomainEvent @event, CancellationToken cancellationToken) { return(_executeMiddlewaresService.ExecuteAsync(@event, cancellationToken, (req, _) => { var eventAsString = _domainEventJsonSerializer.Serialize(req); return _connectionMultiplexer.GetSubscriber().PublishAsync("*", eventAsString); })); }
/// <summary> /// Publish an event to event bus /// </summary> /// <param name="events"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task Publish(IEnumerable <DomainEvent> events, CancellationToken cancellationToken) { if (events == default) { return; } foreach (var domainEvent in events) { await _executeMiddlewaresService.ExecuteAsync(domainEvent, cancellationToken, (@event, _) => { _domainEventsToExecute.Add(@event); return(Task.CompletedTask); }); } }