Exemplo n.º 1
0
        public RabbitMqJobQueueProvider(IEnumerable<string> queues, ConnectionFactory configureAction)
        {
            if (queues == null) throw new ArgumentNullException("queues");
            if (configureAction == null) throw new ArgumentNullException("configureAction");

            _jobQueue = new RabbitMqJobQueue(queues, configureAction);
            _monitoringApi = new RabbitMqMonitoringApi(configureAction, queues.ToArray());
        }
        /// <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))
            {
                var channel = client.Channel.QueueDeclare(queue, true, false, false, null);

                return new EnqueuedAndFetchedCountDto
                {
                    EnqueuedCount = (int) channel.MessageCount
                };
            }
        }
        /// <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(IEnumerable <string> queues, ConnectionFactory configureAction)
        {
            if (queues == null)
            {
                throw new ArgumentNullException("queues");
            }
            if (configureAction == null)
            {
                throw new ArgumentNullException("configureAction");
            }

            _jobQueue      = new RabbitMqJobQueue(queues, configureAction);
            _monitoringApi = new RabbitMqMonitoringApi(configureAction, queues.ToArray());
        }
Exemplo n.º 5
0
        public RabbitMqJobQueueProvider(string[] queues, ConnectionFactory configureAction,
                                        [CanBeNull] Action <IModel> configureConsumer = null)
        {
            if (queues == null)
            {
                throw new ArgumentNullException("queues");
            }
            if (configureAction == null)
            {
                throw new ArgumentNullException("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 <long> GetEnqueuedJobIds(string queue, int from, int perPage)
        {
            using (var client = new RabbitMqJobQueue(new[] { queue }, _factory))
            {
                var consumer = new Subscription(client.Channel, queue);
                var jobIds   = new List <long>();

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

                return(jobIds.Skip(from).Take(perPage));
            }
        }
        /// <remarks>
        /// RabbitMq does not have a Peek feature, the solution is to dequeue all messages
        /// without acknowledging them (noAck = true). 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);

                List<int> jobIds = new List<int>();
                BasicDeliverEventArgs delivery;

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

                return jobIds.Skip(@from).Take(perPage);
            }
        }
 public CleanRabbitMqQueueAttribute(params string[] queues)
 {
     _queues = queues;
     _rabbitMq = new RabbitMqChannel(_queues).CreateQueue();
 }