Example #1
0
        private async Task DeclareEntities(RabbitMQChannel channel)
        {
            var services       = options.Services;
            var channelOptions = channel.Options;
            var channelModel   = channel.Model;

            foreach (var exchangeOptions in channelOptions.ExchangesOptions)
            {
                channelModel.ExchangeDeclare(
                    exchangeOptions.Exchange,
                    exchangeOptions.Type,
                    exchangeOptions.Durable,
                    exchangeOptions.AutoDelete,
                    exchangeOptions.Arguments
                    );
            }

            foreach (var queueOptions in channelOptions.QueuesOptions)
            {
                var queueDeclaration = channelModel.QueueDeclare(
                    queueOptions.Queue,
                    queueOptions.Durable,
                    queueOptions.Exclusive,
                    queueOptions.AutoDelete,
                    queueOptions.Arguments
                    );

                var queue = new RabbitMQQueue(queueOptions, queueDeclaration.QueueName);

                channel.AddQueue(queue);

                services.GetContextAccessor()
                .Set(channel, queue);

                foreach (var action in queueOptions.OnDeclaredActions)
                {
                    await action(services);
                }
            }
        }
Example #2
0
 internal void AddQueue(RabbitMQQueue queue)
 => queues.Add(queue);