/// <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> /// /// </summary> /// <param name="domainEvent"></param> public void Add(DomainEvent domainEvent) { var eventSerialized = _serializer.Serialize(domainEvent); _events.Add(eventSerialized); }