Exemplo n.º 1
0
        /// <summary>
        /// Add an exchange as a singleton.
        /// </summary>
        /// <param name="services">Service collection.</param>
        /// <param name="exchangeName">Exchange name.</param>
        /// <param name="options">Exchange configuration <see cref="RabbitMqExchangeOptions"/>.</param>
        /// <param name="clientExchangeType">Custom client exchange type that defines what functionality is allowed for an exchange.</param>
        /// <returns>Service collection.</returns>
        public static IServiceCollection AddExchange(this IServiceCollection services, string exchangeName, RabbitMqExchangeOptions?options, ClientExchangeType clientExchangeType = ClientExchangeType.Universal)
        {
            var exchangeOptions = options ?? new RabbitMqExchangeOptions();

            ValidateExchangeTypes(exchangeName, exchangeOptions);
            EnsureExchangeHasNotBeenConfiguredYet(services, exchangeName, clientExchangeType);

            var exchange = new RabbitMqExchange(exchangeName, clientExchangeType, exchangeOptions);
            var service  = new ExchangeServiceDescriptor(typeof(RabbitMqExchange), exchange, exchangeName, clientExchangeType);

            services.Add(service);
            return(services);
        }
Exemplo n.º 2
0
        static void StartExchange(IModel channel, RabbitMqExchange exchange)
        {
            channel.ExchangeDeclare(
                exchange: exchange.Name,
                type: exchange.Options.Type,
                durable: exchange.Options.Durable,
                autoDelete: exchange.Options.AutoDelete,
                arguments: exchange.Options.Arguments);

            foreach (var queue in exchange.Options.Queues)
            {
                StartQueue(channel, queue, exchange.Name);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add exchange as singleton.
        /// </summary>
        /// <param name="services">Service collection.</param>
        /// <param name="exchangeName">Exchange name.</param>
        /// <param name="options">Exchange configuration <see cref="RabbitMqExchangeOptions"/>.</param>
        /// <returns>Service collection.</returns>
        public static IServiceCollection AddExchange(this IServiceCollection services, string exchangeName, RabbitMqExchangeOptions options)
        {
            CheckExchangeExists(services, exchangeName);

            var exchangeOptions = options ?? new RabbitMqExchangeOptions();
            var exchange        = new RabbitMqExchange {
                Name = exchangeName, Options = exchangeOptions
            };
            var service = new ExchangeServiceDescriptor(typeof(RabbitMqExchange), exchange)
            {
                ExchangeName = exchangeName
            };

            services.Add(service);
            return(services);
        }