Ejemplo n.º 1
0
        /// <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;
            }));
        }
Ejemplo n.º 2
0
 /// <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);
     }));
 }
Ejemplo n.º 3
0
        /// <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);
                });
            }
        }