// Declare the queue name string QueueName = "QTransactions"; // Create a new connection factory for the queue var factory = new ConnectionFactory(); // Because Rabbit is installed locally, we can run it on localhost factory.HostName = "127.0.0.1"; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { // When reading from a persistent queue, you need to tell that to your consumer const bool durable = true; channel.QueueDeclare(QueueName, durable, false, false, null); var consumer = new QueueingBasicConsumer(channel); // turn auto acknowledge off so we can do it manually. This is so we don't remove items from the queue until we're perfectly happy const bool autoAck = false; channel.BasicConsume(QueueName, autoAck, consumer); System.Console.WriteLine(" [*] Waiting for messages." + "To exit press CTRL+C"); while (true) { var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue(); byte[] body = ea.Body; string message = System.Text.Encoding.UTF8.GetString(body); System.Console.WriteLine(" [x] Processing {0}", message); // Acknowledge message received and processed System.Console.WriteLine(" Processed ", message); channel.BasicAck(ea.DeliveryTag, false); } }