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 ); }
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 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 bool IsInitialized(QueueConfiguration queue) { return queue.IsDirectReplyTo() || queue.AssumeInitialized || _initQueues.Contains(queue.FullQueueName); }
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; }