4

I have an application that I wrote in .NET that can monitor multiple RabbitMq queues using a single consumer.

For example:

 using (IConnection connection = factory.CreateConnection())
{
    using (IModel channel = connection.CreateModel())
    {
        var _consumer = new QueueingBasicConsumer(channel);        
        string[] list = new string[] { "Queue1", "Queue2", "Queue3", "Queue4" };
        _consumer = new QueueingBasicConsumer(channel);
        foreach (string currQueueName in list)
        {
            channel.QueueDeclare(currQueueName, false, false, false, null);
            channel.BasicConsume(currQueueName, true, _consumer);
        }        

        while (true)
        {
            var ea = (BasicDeliverEventArgs)_consumer.Queue.Dequeue();

            var body = ea.Body;
            var message = Encoding.UTF8.GetString(body);
            Console.WriteLine(" [x] Received {0}", message);
            ProcessMessage(message);
        }
    }
}    

Basically, I just want to be able to distribute work across multiple queues, but only have a single application consuming them all (or multiple applications can be deployed and perform the same function).

I'm trying to spread work out across queues so that consumers are taking jobs equally across the queues.

Is this possible using Bunny, or the native Ruby driver?

Alex B.
  • 590
  • 4
  • 17
  • Is it possible to consume from multiple queues using Bunny? Yes. Bunny tutorials are here http://www.rabbitmq.com/tutorials/tutorial-one-ruby.html – old_sound Jun 08 '15 at 11:51

1 Answers1

0

I guess I just needed to spend a bit more time on this.

I'm adding a brief answer just in case this helps anyone else (or if someone wants to provide a cleaner solution :P)

client = Bunny.new
client.start

channel = client.create_channel
queues = %w(testing1 testing2 testing3)
queues.each do |name|
  channel.queue(name).subscribe(timeout: 2) do |info, props, body|
    puts "[#{name}] Got #{body}"
  end
end
loop do      
  sleep 1
end

This effectively does what I was describing in the OP.

Alex B.
  • 590
  • 4
  • 17