Пример #1
0
        private void InitChannel()
        {
            StopChannel();

            _channel = _connection.CreateChannel();

            _channel.ExchangeDeclare(exchange: _queueReferences.DeadLetterExchangeName, type: ExchangeType.Fanout);
            _channel.QueueDeclare(queue: _queueReferences.DeadLetterQueue,
                                  durable: true,
                                  exclusive: false,
                                  autoDelete: false,
                                  arguments: null);
            _channel.QueueBind(_queueReferences.DeadLetterQueue, _queueReferences.DeadLetterExchangeName, routingKey: string.Empty, arguments: null);

            _channel.ExchangeDeclare(exchange: _queueReferences.ExchangeName, type: ExchangeType.Fanout);
            _channel.QueueDeclare(queue: _queueReferences.QueueName,
                                  durable: false,
                                  exclusive: false,
                                  autoDelete: true,
                                  arguments: new Dictionary <string, object>()
            {
                { Headers.XDeadLetterExchange, _queueReferences.DeadLetterExchangeName },
                { Headers.XDeadLetterRoutingKey, _queueReferences.ExchangeName }
            });
            _channel.QueueBind(_queueReferences.QueueName, _queueReferences.ExchangeName, string.Empty, null);

            _channel.CallbackException += OnChannelException;
        }
Пример #2
0
        private void InitChannel()
        {
            _channel?.Dispose();

            _channel = _connection.CreateChannel();

            _channel.ExchangeDeclare(exchange: ExchangeName, type: ExchangeType.Fanout, true, false, null);

            // since we're using a Fanout exchange, we don't specify the name of the queue
            // but we let Rabbit generate one for us. This also means that we need to store the
            // queue name to be able to consume messages from it
            _queue = _channel.QueueDeclare(queue: "DataEventPublisherQueue",
                                           durable: true,
                                           exclusive: false,
                                           autoDelete: false,
                                           arguments: null);

            _channel.QueueBind(_queue.QueueName, ExchangeName, string.Empty, null);

            _channel.CallbackException += (sender, ea) =>
            {
                InitChannel();
                InitSubscription();
            };
        }
Пример #3
0
        private void InitChannel()
        {
            _channel?.Dispose();

            _channel = _connection.CreateChannel();

            _channel.ExchangeDeclare(exchange: _options.DeadLetterExchangeName, type: ExchangeType.Fanout);
            _channel.QueueDeclare(queue: _options.DeadLetterQueue,
                                  durable: true,
                                  exclusive: false,
                                  autoDelete: false,
                                  arguments: null);
            _channel.QueueBind(_options.DeadLetterQueue, _options.DeadLetterExchangeName, routingKey: string.Empty, arguments: null);

            _channel.ExchangeDeclare(exchange: _options.ExchangeName, type: ExchangeType.Fanout);

            _channel.QueueDeclare(queue: _options.QueueName,
                                  durable: false,
                                  exclusive: false,
                                  autoDelete: true,
                                  arguments: null);

            _channel.QueueBind(_options.QueueName, _options.ExchangeName, string.Empty, null);

            _channel.CallbackException += (sender, ea) =>
            {
                InitChannel();
                InitSubscription();
            };
        }
Пример #4
0
        private void InitChannel()
        {
            _channel?.Dispose();

            _channel = _connection.CreateChannel();

            _channel.ExchangeDeclare(exchange: _options.DeadLetterExchangeName, type: ExchangeType.Fanout);
            _channel.QueueDeclare(queue: _options.DeadLetterQueue,
                                  durable: true,
                                  exclusive: false,
                                  autoDelete: false,
                                  arguments: null);
            _channel.QueueBind(_options.DeadLetterQueue, _options.DeadLetterExchangeName, routingKey: string.Empty, arguments: null);

            _channel.ExchangeDeclare(exchange: _options.ExchangeName, type: ExchangeType.Fanout);
            _channel.QueueDeclare(queue: _options.QueueName,
                                  durable: false,
                                  exclusive: false,
                                  autoDelete: true,
                                  arguments: new Dictionary <string, object>()
            {
                { "x-dead-letter-exchange", _options.DeadLetterExchangeName },
                { "x-dead-letter-routing-key", _options.ExchangeName }
            });
            _channel.QueueBind(_options.QueueName, _options.ExchangeName, string.Empty, null);

            _channel.CallbackException += (sender, ea) =>
            {
                _logger.LogError(ea.Exception, "the RabbitMQ Channel has encountered an error: {ExceptionMessage}", ea.Exception.Message);

                InitChannel();
                InitSubscription();
            };
        }
 public RabbitPublisher(IBusConnection connection)
 {
     _connection = connection ?? throw new ArgumentNullException(nameof(connection));
     _channel    = _connection.CreateChannel();
     _channel.ExchangeDeclare(exchange: ExchangeName, type: ExchangeType.Fanout);
     _properties = _channel.CreateBasicProperties();
 }
Пример #6
0
        private void InitChannel()
        {
            StopChannel();

            _channel = _connection.CreateChannel();

            _logger.LogInformation($"initializing queue '{_queueReferences.DeadLetterQueue}' on exchange '{_queueReferences.DeadLetterExchangeName}'...");

            _channel.ExchangeDeclare(exchange: _queueReferences.DeadLetterExchangeName, type: ExchangeType.Topic);
            _channel.QueueDeclare(queue: _queueReferences.DeadLetterQueue,
                                  durable: true,
                                  exclusive: false,
                                  autoDelete: false,
                                  arguments: null);
            _channel.QueueBind(_queueReferences.DeadLetterQueue, _queueReferences.DeadLetterExchangeName, routingKey: string.Empty, arguments: null);

            _logger.LogInformation($"initializing queue '{_queueReferences.QueueName}' on exchange '{_queueReferences.ExchangeName}'...");

            _channel.ExchangeDeclare(exchange: _queueReferences.ExchangeName, type: ExchangeType.Topic);
            _channel.QueueDeclare(queue: _queueReferences.QueueName,
                                  durable: false,
                                  exclusive: false,
                                  autoDelete: true,
                                  arguments: new Dictionary <string, object>()
            {
                { Headers.XDeadLetterExchange, _queueReferences.DeadLetterExchangeName },
                { Headers.XDeadLetterRoutingKey, _queueReferences.ExchangeName }
            });
            _channel.QueueBind(queue: _queueReferences.QueueName,
                               exchange: _queueReferences.ExchangeName,
                               routingKey: _queueReferences.RoutingKey,
                               arguments: null);

            _channel.CallbackException += OnChannelException;
        }
Пример #7
0
        public RabbitPublisher(IBusConnection connection, string exchangeName)
        {
            if (string.IsNullOrWhiteSpace(exchangeName))
            {
                throw new ArgumentException($"'{nameof(exchangeName)}' cannot be null or whitespace", nameof(exchangeName));
            }
            _exchangeName = exchangeName;

            _connection = connection ?? throw new ArgumentNullException(nameof(connection));
            _channel    = _connection.CreateChannel();
            _channel.ExchangeDeclare(exchange: _exchangeName, type: ExchangeType.Fanout);
            _properties = _channel.CreateBasicProperties();
        }
Пример #8
0
        public HttpEventPublisher(IBusConnection connection, RequestResponse requestResponse)
        {
            _connection = connection ?? throw new ArgumentNullException(nameof(connection));
            _channel    = _connection.CreateChannel();
            _channel.ExchangeDeclare(exchange: ExchangeName, type: ExchangeType.Fanout);
            _properties = _channel.CreateBasicProperties();

            _requestResponse = requestResponse;

            _timer           = new Timer(requestResponse.Interval);
            _timer.Elapsed  += RaiseHttpEvent;
            _timer.AutoReset = true;
            _timer.Enabled   = true;
        }
        public RabbitPublisher(IBusConnection connection, string exchangeName, IEncoder encoder, ILogger <RabbitPublisher> logger)
        {
            if (string.IsNullOrWhiteSpace(exchangeName))
            {
                throw new ArgumentException($"'{nameof(exchangeName)}' cannot be null or whitespace", nameof(exchangeName));
            }

            _connection   = connection ?? throw new ArgumentNullException(nameof(connection));
            _encoder      = encoder ?? throw new ArgumentNullException(nameof(encoder));
            _logger       = logger ?? throw new ArgumentNullException(nameof(logger));
            _exchangeName = exchangeName;

            _channel = _connection.CreateChannel();
            _channel.ExchangeDeclare(exchange: exchangeName, type: ExchangeType.Fanout);
            _properties            = _channel.CreateBasicProperties();
            _properties.Persistent = true;
        }
Пример #10
0
        private void InitChannel()
        {
            _channel?.Dispose();
            _channel = _connection.CreateChannel();
            _channel.ExchangeDeclare(exchange: ExchangeName, type: ExchangeType.Fanout);

            // Since we're using a Fanout exchange we let Rabbit generate a
            // queue name for us. This also means that we need to store
            // the queue name to be able to consume messages from it
            _queue = _channel.QueueDeclare(queue: string.Empty,
                                           durable: false,
                                           exclusive: false,
                                           autoDelete: true,
                                           arguments: null);
            _channel.QueueBind(queue: String.Empty, exchange: ExchangeName, routingKey: "");

            _channel.CallbackException += (sender, ea) => {
                InitChannel();
                InitSubscription();
            };
        }