Beispiel #1
0
        internal void Initialize(RabbitMQOptions options)
        {
            _options = options;
            _logger.LogInformation($"RabbitMQ Host: {_options.Host}, Port: {_options.Port}");
            var connectionFactory = new ConnectionFactory {
                HostName = _options.Host, DispatchConsumersAsync = true
            };

            if (_options.Port > 0)
            {
                connectionFactory.Port = _options.Port;
            }

            if (!string.IsNullOrWhiteSpace(_options.UserName))
            {
                connectionFactory.UserName = _options.UserName;
            }

            if (!string.IsNullOrWhiteSpace(_options.Password))
            {
                connectionFactory.Password = _options.Password;
            }

            _connection = connectionFactory.CreateConnection();
            _modelDict  = new ConcurrentDictionary <string, IModel>();
        }
 public RabbitMQMessageQueue(IOptions <RabbitMQOptions> options, ILoggerFactory loggerFactory)
 {
     _logger     = loggerFactory.CreateLogger <RabbitMQMessageQueue>();
     _options    = options.Value;
     _connection = new PersistentConnection(CreateConnectionFactory(),
                                            loggerFactory.CreateLogger <PersistentConnection>(), _options.RetryCount);
     CreateConsumerChannel();
 }
Beispiel #3
0
        public RabbitMQMessageQueue(IOptions <RabbitMQOptions> options, ILoggerFactory loggerFactory)
        {
            _logger     = loggerFactory.CreateLogger <RabbitMQMessageQueue>();
            _options    = options.Value;
            _connection = new PersistentConnection(CreateConnectionFactory(),
                                                   loggerFactory.CreateLogger <PersistentConnection>(), _options.RetryCount);

            if (!_connection.IsConnected)
            {
                _connection.TryConnect();
            }

            _logger.LogTrace("Creating RabbitMQ publish channel");

            _publishChannel = _connection.CreateModel();
            _publishChannel.ExchangeDeclare(exchange: _options.Exchange, type: "direct", durable: true);
        }