title: C# Consuming / Reading message every x interval with y batch size From Rabbit MQ
body: <p>I was using Rabbit MQ for processing messages in sequential order. Now I have scenario, where don't need to consume message immediately, but I would like to consume/ read messages from MQ every 1(x) minute with batch size of 20(y)</p>
  
  <p>So I can process this 20 messages in single time and save to DB in single call instead of calling 20 times for each message.</p>
  
  <p>So how to receive/consume messages in batch on every x interval.</p>
  
  <p>I have seen following information, <a href="https://stackoverflow.com/questions/38844610/consume-messages-in-batches-rabbitmq">Consume messages in batches - RabbitMQ</a> and <a href="https://stackoverflow.com/questions/32309155/rabbitmq-retrieve-multiple-messages-using-single-synchronous-call-using-net">Rabbitmq retrieve multiple messages using single synchronous call using .NET</a></p>
  
  <p>I tried to implement 2nd question implementation (questions/32309155) but not working, didn't understand "consumer.Received" will receive **_fetchSize ==> 20 ** means, it will receive 20 messages in single read? or how it will work, because I changed fetchsize to 10, but consumer.received is receiving single message.</p>
  
  <pre><code>using (var connection = factory.CreateConnection())
          {
              using (var channel = connection.CreateModel())
              {
                  channel.BasicQos(0, 1, false);
                  channel.ExchangeDeclare("helloExchange", type:"direct");
                  channel.QueueDeclare(queue: "hello", durable: true, exclusive: false, autoDelete: false,
                      arguments: null);
  
                  channel.QueueBind("hello", "helloExchange", routingKey:"hello");
  
                  var consumer = new EventingBasicConsumer(channel);
  
                  consumer.Received += (model, ea) =&gt;
                  {
                      bool canAck = false;
                      var retryCount = 0;
  
  
  
                      try
                      {
                          var body = ea.Body;
                          var message = Encoding.UTF8.GetString(body);
                         // DO PROCESS MESSAGE HERE
                          Console.WriteLine($"{typeof(MyConsumer).Name} Message consumed {message}");
                          canAck = true;
                      }
                      catch (Exception ex)
                      {canAck = false;
                        // LOG ERROR
                      }
  
                      try
                      {
                          if (canAck)
                          {
                              channel.BasicAck(ea.DeliveryTag, false);
                          }
                          else
                          {
                              channel.BasicNack(ea.DeliveryTag, false, false);
                          }
                      }
                      catch (AlreadyClosedException ex)
                      {
                          Console.WriteLine(ex.Message + " &gt;&gt; RabbitMQ is closed!");
                      }
                  };
                  channel.BasicConsume(queue: "hello", autoAck: false, consumer: consumer);
  
                  Console.WriteLine(" Press [enter] to exit.");
                  Console.ReadLine();
              }
          }
  </code></pre>