Example #1
0
		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 Task CreateExchangeAsync(ExchangeConfiguration exchange)
        {
            Task existingTask;
            if (_initExchanges.TryGetValue(exchange.ExchangeName, out existingTask))
            {
                return existingTask;
            }

            if (exchange.IsDefaultExchange() || exchange.AssumeInitialized)
            {
                _initExchanges.TryAdd(exchange.ExchangeName, _completed);
                return _completed;
            }

            var exchangeTask = _channelFactory
                    .GetChannelAsync()
                    .ContinueWith(tChannel =>
                    {
                        tChannel.Result.ExchangeDeclare(
                            exchange.ExchangeName,
                            exchange.ExchangeType,
                            exchange.Durable,
                            exchange.AutoDelete,
                            exchange.Arguments);
                    });
            _initExchanges.TryAdd(exchange.ExchangeName, exchangeTask);
            return exchangeTask;
        }
Example #3
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
				);
		}
Example #4
0
 public DefaultStrategy(IMessageSerializer serializer, INamingConventions conventions, IBasicPropertiesProvider propertiesProvider, ITopologyProvider topologyProvider, IChannelFactory channelFactory)
 {
     _serializer = serializer;
     _propertiesProvider = propertiesProvider;
     _topologyProvider = topologyProvider;
     _channelFactory = channelFactory;
     _errorExchangeCfg = ExchangeConfiguration.Default;
     _errorExchangeCfg.ExchangeName = conventions.ErrorExchangeNamingConvention();
 }
		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
			};
		}
Example #6
0
		public Task DeclareExchangeAsync(ExchangeConfiguration exchange)
		{
			if (IsInitialized(exchange))
			{
				return _completed;
			}

			var scheduled = new ScheduledExchangeTask(exchange);
			_topologyTasks.Enqueue(scheduled);
			EnsureWorker();
			return scheduled.TaskCompletionSource.Task;
		}
Example #7
0
		protected void DeclareExchange(ExchangeConfiguration config, IModel channel = null)
		{
			if (config.IsDefaultExchange() || config.AssumeInitialized)
			{
				return;
			}
			_logger.LogDebug($"Declaring exchange\n  Name: {config.ExchangeName}\n  Type: {config.ExchangeType}\n  Durable: {config.Durable}\n  Autodelete: {config.AutoDelete}");
			channel = channel ?? ChannelFactory.GetChannel();
			channel
				.ExchangeDeclare(
					exchange: config.ExchangeName,
					type: config.ExchangeType
				);
		}
        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
                        );
                });
        }
Example #9
0
			public ScheduledExchangeTask(ExchangeConfiguration exchange)
			{
				Configuration = exchange;
			}
Example #10
0
		private void DeclareExchange(ExchangeConfiguration exchange)
		{
			if (IsInitialized(exchange))
			{
				return;
			}

			_logger.LogInformation($"Declaring exchange '{exchange.ExchangeName}'.");
			var channel = GetOrCreateChannel();
			channel.ExchangeDeclare(
				exchange.ExchangeName,
				exchange.ExchangeType,
				exchange.Durable,
				exchange.AutoDelete,
				exchange.Arguments);
			if (!exchange.AutoDelete)
			{
				_initExchanges.Add(exchange.ExchangeName);
			}
		}
Example #11
0
		public bool IsInitialized(ExchangeConfiguration exchange)
		{
			return exchange.IsDefaultExchange() || exchange.AssumeInitialized || _initExchanges.Contains(exchange.ExchangeName);
		}
Example #12
0
		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 ResponderConfiguration()
		{
			Exchange = new ExchangeConfiguration();
			Queue = new QueueConfiguration();
			NoAck = true;
		}
		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 PublishConfigurationBuilder(ExchangeConfiguration defaultExchange = null, string routingKey =null)
		{
			_exchange = new ExchangeConfigurationBuilder(defaultExchange);
			_routingKey = routingKey ?? _oneOrMoreWords;
		}
		public RequestConfiguration()
		{
			Exchange = new ExchangeConfiguration();
			ReplyQueue = new QueueConfiguration();
			NoAck = true;
		}
 public SubscriptionConfigurationBuilder(QueueConfiguration initialQueue, ExchangeConfiguration initialExchange)
 {
     _exchangeBuilder = new ExchangeConfigurationBuilder(initialExchange);
     _queueBuilder = new QueueConfigurationBuilder(initialQueue);
 }