/// <remarks>
        /// Calling QueueDeclare will return the number of messages that exist in the queue.
        /// QueueDeclare is idempotent so it can be called regardless if the queue exists.
        /// </remarks>
        public EnqueuedAndFetchedCountDto GetEnqueuedAndFetchedCount(string queue)
        {
            using (var client = new RabbitMqJobQueue(new[] { queue }, _factory, null))
            {
                var channel = client.Channel.QueueDeclare(queue, true, false, false, null);

                return(new EnqueuedAndFetchedCountDto
                {
                    EnqueuedCount = (int)channel.MessageCount
                });
            }
        }
        public RabbitMqJobQueueProvider(string[] queues, ConnectionFactory configureAction,
                                        [CanBeNull] Action <IModel> configureConsumer = null)
        {
            if (queues == null)
            {
                throw new ArgumentNullException(nameof(queues));
            }
            if (configureAction == null)
            {
                throw new ArgumentNullException(nameof(configureAction));
            }

            _jobQueue      = new RabbitMqJobQueue(queues, configureAction, configureConsumer);
            _monitoringApi = new RabbitMqMonitoringApi(configureAction, queues);
        }
        /// <remarks>
        /// RabbitMq does not have a Peek feature, the solution is to dequeue all messages
        /// with acknowledgments required (noAck = false). After all messages have been read
        /// we dispose the RabbitMqJobQueue causing the channel to close. All unack'd
        /// messages then get requeued in order.
        /// </remarks>
        public IEnumerable <int> GetEnqueuedJobIds(string queue, int @from, int perPage)
        {
            using (var client = new RabbitMqJobQueue(new[] { queue }, _factory))
            {
                var consumer = new Subscription(client.Channel, queue, true);

                var jobIds = new List <int>();

                while (consumer.Next(1000, out var delivery))
                {
                    var body = Encoding.UTF8.GetString(delivery.Body);
                    jobIds.Add(Convert.ToInt32(body));
                }

                return(jobIds.Skip(@from).Take(perPage));
            }
        }