Example #1
0
        public void ShouldDeclareQueueWithDeadLetterRoutingKeyAndExchange()
        {
            // GIVEN
            var queueName            = "queueName";
            var durable              = false;
            var exclusive            = false;
            var autoDelete           = false;
            var deadLetterRoutingKey = "dlqQueueName";
            var deadLetterExchange   = "dlqExchange";

            var expectedArguments = new Dictionary <string, object>();

            expectedArguments.Add(DeclarationService.QUEUE_DEAD_LETTER_ROUTING_KEY_ARGUMENT, deadLetterRoutingKey);
            expectedArguments.Add(DeclarationService.QUEUE_DEAD_LETTER_EXCHANGE_ARGUMENT, deadLetterExchange);

            var settings = new OwlerySettings {
                Queues = new Dictionary <string, QueueSettings>()
                {
                    {
                        "Queue",
                        new QueueSettings()
                        {
                            QueueName  = queueName,
                            Durable    = durable,
                            Exclusive  = exclusive,
                            AutoDelete = autoDelete,

                            DeadLetterRoutingKey = deadLetterRoutingKey,
                            DeadLetterExchange   = deadLetterExchange,
                        }
                    }
                }
            };

            var service = new DeclarationService(
                Options.Create <OwlerySettings>(settings),
                this.logger);

            // WHEN
            service.DeclareAll(this.model.Object);

            // THEN
            this.model.Verify(
                m => m.QueueDeclare(
                    It.Is <string>(s => s == queueName),
                    It.Is <bool>(b => b == durable),
                    It.Is <bool>(b => b == exclusive),
                    It.Is <bool>(b => b == autoDelete),
                    It.Is <IDictionary <string, object> >(d =>
                                                          deadLetterExchange == (string)d[DeclarationService.QUEUE_DEAD_LETTER_EXCHANGE_ARGUMENT] &&
                                                          deadLetterRoutingKey == (string)d[DeclarationService.QUEUE_DEAD_LETTER_ROUTING_KEY_ARGUMENT]
                                                          )
                    )
                );
            this.model.VerifyNoOtherCalls();
        }
Example #2
0
        public RabbitConnection(
            IDeclarationService declarationService,
            IServiceProvider serviceProvider,
            IConfiguration configuration,
            IOptions <OwlerySettings> settings,
            ILoggerFactory factory)
        {
            this.declarationService = declarationService;
            this.serviceProvider    = serviceProvider;
            this.configuration      = configuration;
            this.settings           = settings.Value;
            this.logger             = factory.CreateLogger <RabbitConnection>();
            this.loggerFactory      = factory;

            this.consumers = new List <RabbitConsumer>();
        }
Example #3
0
        public void ShouldDeclareExchangesWithAttributes()
        {
            // GIVEN
            var exchangeName = "exchangeName";
            var type         = "exchangeType";
            var durable      = false;
            var autoDelete   = false;
            var arguments    = new Dictionary <string, object>();

            var settings = new OwlerySettings {
                Exchanges = new Dictionary <string, ExchangeSettings>()
                {
                    {
                        "Exchange",
                        new ExchangeSettings()
                        {
                            ExchangeName = exchangeName,
                            Type         = type,
                            Durable      = durable,
                            AutoDelete   = autoDelete,
                            Arguments    = arguments,
                        }
                    }
                }
            };

            var service = new DeclarationService(
                Options.Create <OwlerySettings>(settings),
                this.logger);

            // WHEN
            service.DeclareAll(this.model.Object);

            // THEN
            this.model.Verify(
                m => m.ExchangeDeclare(
                    It.Is <string>(s => s == exchangeName),
                    It.Is <string>(s => s == type),
                    It.Is <bool>(b => b == durable),
                    It.Is <bool>(b => b == autoDelete),
                    It.Is <IDictionary <string, object> >(d => d == arguments)
                    )
                );
            this.model.VerifyNoOtherCalls();
        }
Example #4
0
        public void ShouldBindQueueToExchangeWithAttributes()
        {
            // GIVEN
            var queueName    = "exchangeName";
            var exchangeName = "exchangeName";
            var routingKey   = "routingKey";
            var arguments    = new Dictionary <string, object>();

            var settings = new OwlerySettings {
                Bindings = new Dictionary <string, BindingSettings>()
                {
                    {
                        "Binding",
                        new BindingSettings()
                        {
                            QueueName    = queueName,
                            ExchangeName = exchangeName,
                            RoutingKey   = routingKey,
                            Arguments    = arguments,
                        }
                    }
                }
            };

            var service = new DeclarationService(
                Options.Create <OwlerySettings>(settings),
                this.logger);

            // WHEN
            service.DeclareAll(this.model.Object);

            // THEN
            this.model.Verify(
                m => m.QueueBind(
                    It.Is <string>(s => s == queueName),
                    It.Is <string>(s => s == exchangeName),
                    It.Is <string>(s => s == routingKey),
                    It.Is <IDictionary <string, object> >(d => d == arguments)
                    )
                );
            this.model.VerifyNoOtherCalls();
        }
 public BasicPropertiesHandler(IOptions <OwlerySettings> settings)
 {
     this.settings = settings.Value;
 }
Example #6
0
 public DeclarationService(IOptions <OwlerySettings> settings, ILogger <DeclarationService> logger)
 {
     this.settings = settings.Value;
     this.logger   = logger;
 }