Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="stoppingToken"></param>
        /// <returns></returns>
        protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            using var scope = _serviceScopeFactory.CreateScope();

            var channel = scope.ServiceProvider.GetRequiredService <RabbitMqConnectionFactory>().Channel();

            var exchangeName = scope.ServiceProvider.GetRequiredService <IOptions <RabbitMqConfigParams> >().Value.ExchangeName;

            var retryDomainEventExchange      = RabbitMqExchangeNameFormatter.Retry(exchangeName);
            var deadLetterDomainEventExchange = RabbitMqExchangeNameFormatter.DeadLetter(exchangeName);

            channel.ExchangeDeclare(exchangeName, ExchangeType.Topic);
            channel.ExchangeDeclare(retryDomainEventExchange, ExchangeType.Topic);
            channel.ExchangeDeclare(deadLetterDomainEventExchange, ExchangeType.Topic);

            foreach (var subscriberInformation in DomainEventSubscriberInformationService.All())
            {
                var domainEventsQueueName = RabbitMqQueueNameFormatter.Format(subscriberInformation);
                var retryQueueName        = RabbitMqQueueNameFormatter.FormatRetry(subscriberInformation);
                var deadLetterQueueName   = RabbitMqQueueNameFormatter.FormatDeadLetter(subscriberInformation);
                var subscribedEvent       = EventNameSubscribed(subscriberInformation);

                var queue = channel.QueueDeclare(domainEventsQueueName, true, false, false);

                var retryQueue = channel.QueueDeclare(retryQueueName, true, false, false,
                                                      RetryQueueArguments(exchangeName, domainEventsQueueName));

                var deadLetterQueue = channel.QueueDeclare(deadLetterQueueName, true, false, false);

                channel.QueueBind(queue, exchangeName, domainEventsQueueName);
                channel.QueueBind(retryQueue, retryDomainEventExchange, domainEventsQueueName);
                channel.QueueBind(deadLetterQueue, deadLetterDomainEventExchange, domainEventsQueueName);
                channel.QueueBind(queue, exchangeName, subscribedEvent);
            }

            return(scope.ServiceProvider.GetRequiredService <RabbitMqDomainEventsConsumer>().Consume());
        }
Example #2
0
 private void SendToRetry(BasicDeliverEventArgs ea, string queue)
 {
     SendMessageTo(RabbitMqExchangeNameFormatter.Retry(_rabbitMqParams.Value.ExchangeName), ea, queue);
 }