[rabbitmq-discuss] Reading multiple messages in RabbitMQ

Demi Zike habtdemis at gmail.com
Wed Jul 20 15:50:01 BST 2011


Hi,

I use Subscription from the RabbitMQ.Client.MessagePatterns namespace to
subscribe to multiple queues. I then read messages based on the subscription
(code below). However, I am not able to read messages other than the first
one. i.e. Whether I try to read from multiple queues(subscriptions) or a
single queue(subscription). I do Ack() at each iteration of the message
reading. Could you see where the run time error originated at for me?

Thanks

private List<Subscription> subscriptions = new List<Subscription>();
Subscription sub = null;


    public Measurement readMessage()
           {
            Measurement m = new Measurement();
            foreach(Subscription element in subscriptions)
            {
                if( element.QueueName == null)
                {
                    m = null;
                }
                else
                {
                    BasicDeliverEventArgs ev = element.Next();
                    if( ev != null) {
                        m = Measurement.AltDeSerialize( ev.Body );
                        m.id = element.QueueName;
                        element.Ack();
                        return m;
                    }
                    m =  null;
                    element.Ack();

                }
            }
            System.Console.WriteLine("No message in the queue(s) at this
time.");
            return m;
        }

        public void subscribeToQueue(string queueName)
        {
            sub = new Subscription(channel, queueName);
            subscriptions.Add(sub);
        }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20110720/30a7e8ef/attachment.htm>


More information about the rabbitmq-discuss mailing list