Exemple #1
0
		protected void BindQueue(QueueConfiguration queue, ExchangeConfiguration exchange, string routingKey)
		{
			if (exchange.IsDefaultExchange())
			{
				/*
					"The default exchange is implicitly bound to every queue,
					with a routing key equal to the queue name. It it not possible
					to explicitly bind to, or unbind from the default exchange."
				*/
				return;
			}
			if (queue.IsDirectReplyTo())
			{
				/*
					"Consume from the pseudo-queue amq.rabbitmq.reply-to in no-ack mode. There is no need to
					declare this "queue" first, although the client can do so if it wants."
					- https://www.rabbitmq.com/direct-reply-to.html
				*/
				return;
			}
			_logger.LogDebug($"Binding queue {queue.QueueName} to exchange {exchange.ExchangeName} with routing key {routingKey}");
			ChannelFactory
				.GetChannel()
				.QueueBind(
					queue: queue.FullQueueName,
					exchange: exchange.ExchangeName,
					routingKey: routingKey
				);
		}
		public Task BindQueueAsync(QueueConfiguration queue, ExchangeConfiguration exchange, string routingKey)
		{
			if (exchange.IsDefaultExchange())
			{
				/*
					"The default exchange is implicitly bound to every queue,
					with a routing key equal to the queue name. It it not possible
					to explicitly bind to, or unbind from the default exchange."
				*/
				return _completed;
			}
			if (queue.IsDirectReplyTo())
			{
				/*
					"Consume from the pseudo-queue amq.rabbitmq.reply-to in no-ack mode. There is no need to
					declare this "queue" first, although the client can do so if it wants."
					- https://www.rabbitmq.com/direct-reply-to.html
				*/
				return _completed;
			}
			var bindKey = $"{queue.FullQueueName}_{exchange.ExchangeName}_{routingKey}";
			if (_queueBinds.Contains(bindKey))
			{
				return _completed;
			}
			var scheduled = new ScheduledBindQueueTask
			{
				Queue = queue,
				Exchange = exchange,
				RoutingKey = routingKey
			};
			_topologyTasks.Enqueue(scheduled);
			EnsureWorker();
			return scheduled.TaskCompletionSource.Task;
		}
		public ResponderConfigurationBuilder(QueueConfiguration defaultQueue = null, ExchangeConfiguration defaultExchange = null)
		{
			_exchangeBuilder = new ExchangeConfigurationBuilder(defaultExchange);
			_queueBuilder = new QueueConfigurationBuilder(defaultQueue);
			Configuration = new ResponderConfiguration
			{
				Queue = _queueBuilder.Configuration,
				Exchange = _exchangeBuilder.Configuration,
				RoutingKey = _queueBuilder.Configuration.QueueName
			};
		}
		public Task DeclareQueueAsync(QueueConfiguration queue)
		{
			if (IsInitialized(queue))
			{
				return _completed;
			}

			var scheduled = new ScheduledQueueTask(queue);
			_topologyTasks.Enqueue(scheduled);
			EnsureWorker();
			return scheduled.TaskCompletionSource.Task;
		}
        public Task BindQueueAsync(QueueConfiguration queue, ExchangeConfiguration exchange, string routingKey)
        {
            var queueTask = CreateQueueAsync(queue);
            var exchangeTask = CreateExchangeAsync(exchange);
            var channelTask = _channelFactory.CreateChannelAsync();

            return Task
                .WhenAll(queueTask, exchangeTask, channelTask)
                .ContinueWith(t =>
                {
                    channelTask.Result
                        .QueueBind(
                            queue: queue.FullQueueName,
                            exchange: exchange.ExchangeName,
                            routingKey: routingKey
                        );
                });
        }
Exemple #6
0
		protected void DeclareQueue(QueueConfiguration queue, IModel channel = null)
		{
			if (queue.IsDirectReplyTo())
			{
				/*
					"Consume from the pseudo-queue amq.rabbitmq.reply-to in no-ack mode. There is no need to
					declare this "queue" first, although the client can do so if it wants."
					- https://www.rabbitmq.com/direct-reply-to.html
				*/
				return;
			}
			channel = channel ?? ChannelFactory.GetChannel();
			channel
				.QueueDeclare(
					queue: queue.FullQueueName,
					durable: queue.Durable,
					exclusive: queue.Exclusive,
					autoDelete: queue.AutoDelete,
					arguments: queue.Arguments
				);
			_logger.LogDebug($"Declaring queue\n  Name: {queue.FullQueueName}\n  Exclusive: {queue.Exclusive}\n  Durable: {queue.Durable}\n  Autodelete: {queue.AutoDelete}");
		}
			public ScheduledQueueTask(QueueConfiguration queue)
			{
				Configuration = queue;
			}
		private void DeclareQueue(QueueConfiguration queue)
		{
			if (IsInitialized(queue))
			{
				return;
			}

			_logger.LogInformation($"Declaring queue '{queue.FullQueueName}'.");

			var channel = GetOrCreateChannel();
			channel.QueueDeclare(
				queue.FullQueueName,
				queue.Durable,
				queue.Exclusive,
				queue.AutoDelete,
				queue.Arguments);

			if (queue.AutoDelete)
			{
				_initQueues.Add(queue.FullQueueName);
			}
		}
		public bool IsInitialized(QueueConfiguration queue)
		{
			return queue.IsDirectReplyTo() || queue.AssumeInitialized || _initQueues.Contains(queue.FullQueueName);
		}
		public Task UnbindQueueAsync(QueueConfiguration queue, ExchangeConfiguration exchange, string routingKey)
		{
			var scheduled = new ScheduledUnbindQueueTask
			{
				Queue = queue,
				Exchange = exchange,
				RoutingKey = routingKey
			};
			_topologyTasks.Enqueue(scheduled);
			EnsureWorker();
			return scheduled.TaskCompletionSource.Task;
		}
		public SubscriptionConfiguration()
		{
			Exchange = new ExchangeConfiguration();
			Queue = new QueueConfiguration();
		}
		public SubscriptionConfigurationBuilder(QueueConfiguration initialQueue, ExchangeConfiguration initialExchange, string routingKey)
		{
			_exchangeBuilder = new ExchangeConfigurationBuilder(initialExchange);
			_queueBuilder = new QueueConfigurationBuilder(initialQueue);
			_routingKey = routingKey;
		}
 public PublishConfigurationBuilder(QueueConfiguration replyQueue = null, ExchangeConfiguration defaultExchange = null)
 {
     _queue = new QueueConfigurationBuilder(replyQueue);
     _exchange = new ExchangeConfigurationBuilder(defaultExchange);
 }
		public ResponderConfiguration()
		{
			Exchange = new ExchangeConfiguration();
			Queue = new QueueConfiguration();
			NoAck = true;
		}
Exemple #15
0
 public static bool IsDirectReplyTo(this QueueConfiguration queue)
 {
     return(string.Equals(queue.QueueName, _directQueueName, StringComparison.CurrentCultureIgnoreCase));
 }
        public Task CreateQueueAsync(QueueConfiguration queue)
        {
            Task existingTask;
            if (_initQueues.TryGetValue(queue.FullQueueName, out existingTask))
            {
                return existingTask;
            }

            if (queue.IsDirectReplyTo())
            {
                /*
                    "Consume from the pseudo-queue amq.rabbitmq.reply-to in no-ack mode. There is no need to
                    declare this "queue" first, although the client can do so if it wants."
                    - https://www.rabbitmq.com/direct-reply-to.html
                */
                _initQueues.TryAdd(queue.FullQueueName, _completed);
                return _completed;
            }

            var queueTask = _channelFactory
                .GetChannelAsync()
                .ContinueWith(tChannel =>
                {
                    tChannel.Result.QueueDeclare(
                        queue.FullQueueName,
                        queue.Durable,
                        queue.Exclusive,
                        queue.AutoDelete,
                        queue.Arguments);
                });
            _initQueues.TryAdd(queue.FullQueueName, queueTask);
            return queueTask;
        }
		public RequestConfiguration()
		{
			Exchange = new ExchangeConfiguration();
			ReplyQueue = new QueueConfiguration();
			NoAck = true;
		}
 public SubscriptionConfigurationBuilder(QueueConfiguration initialQueue, ExchangeConfiguration initialExchange)
 {
     _exchangeBuilder = new ExchangeConfigurationBuilder(initialExchange);
     _queueBuilder = new QueueConfigurationBuilder(initialQueue);
 }