Esempio n. 1
0
        private void InitializeConsumer(IModel channel)
        {
            channel.BasicQos(0, 1, false);
            var consumer = _persistentConnection.CreateConsumer(channel);

            consumer.Received += (sender, ea) => _rabbitConsumerHandler.HandleAsync(channel, ea);

            channel.BasicConsume(queue: _rabbitMqEventBusOptions.QueueName, autoAck: false, consumer);
            channel.CallbackException += (sender, ea) =>
            {
                channel.Dispose();
                InitializeConsumer(_persistentConnection.CreateModel());
            };

            _logger.LogInformation("Consumer initialized successfully");
        }
Esempio n. 2
0
        public void SetUp()
        {
            _rabbitMqPersistentConnection = Substitute.For <IRabbitMqPersistentConnection>();
            _rabbitConsumerHandler        = Substitute.For <IRabbitConsumerHandler>();
            var rabbitMqEventBusOptions = Substitute.For <IOptions <RabbitMqEventBusOptions> >();
            var value = Substitute.For <RabbitMqEventBusOptions>();

            rabbitMqEventBusOptions.Value.Returns(value);
            _rabbitMqEventBusOptions = value;
            var queueName    = Guid.NewGuid().ToString();
            var exchangeName = Guid.NewGuid().ToString();

            value.QueueName.Returns(queueName);
            value.ExchangeName.Returns(exchangeName);
            _model = Substitute.For <IModel>();
            _rabbitMqPersistentConnection.CreateModel().Returns(_model);
            _consumer = Substitute.For <EventingBasicConsumer>(Substitute.For <IModel>());
            _rabbitMqPersistentConnection.CreateConsumer(_model).Returns(_consumer);

            _sut = new RabbitConsumerInitializer(_rabbitMqPersistentConnection, rabbitMqEventBusOptions, _rabbitConsumerHandler, Substitute.For <ILogger <RabbitConsumerInitializer> >());
        }