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; }
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 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; }
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 bool IsInitialized(ExchangeConfiguration exchange) { return exchange.IsDefaultExchange() || exchange.AssumeInitialized || _initExchanges.Contains(exchange.ExchangeName); }