private void SetQosAndCreateConsumers() { if (!AcknowledgeMode.IsAutoAck() && !Cancelled) { // Set basicQos before calling basicConsume (otherwise if we are not acking the broker // will send blocks of 100 messages) try { Channel.BasicQos(0, PrefetchCount, true); } catch (Exception e) { ActiveObjectCounter.Release(this); throw new RabbitIOException(e); } } try { if (!Cancelled) { foreach (var queueName in Queues) { if (!MissingQueues.Contains(queueName)) { ConsumeFromQueue(queueName); } } } } catch (Exception e) { throw RabbitExceptionTranslator.ConvertRabbitAccessException(e); } }
private void HandleDeclarationException(int passiveDeclareRetries, DeclarationException e) { if (passiveDeclareRetries > 0 && Channel.IsOpen) { Logger?.LogWarning(e, "Queue declaration failed; retries left={retries}", passiveDeclareRetries); try { Thread.Sleep(FailedDeclarationRetryInterval); } catch (Exception e1) { Declaring = false; ActiveObjectCounter.Release(this); throw RabbitExceptionTranslator.ConvertRabbitAccessException(e1); } } else if (e.FailedQueues.Count < Queues.Count) { Logger?.LogWarning("Not all queues are available; only listening on those that are - configured: {queues}; not available: {notavail}", string.Join(',', Queues), string.Join(',', e.FailedQueues)); lock (MissingQueues) { foreach (var q in e.FailedQueues) { MissingQueues.Add(q); } } LastRetryDeclaration = DateTimeOffset.Now.ToUnixTimeMilliseconds(); } else { Declaring = false; ActiveObjectCounter.Release(this); throw new QueuesNotAvailableException("Cannot prepare queue for listener. Either the queue doesn't exist or the broker will not allow us to use it.", e); } }