[rabbitmq-discuss] Problem Extending DefaultBasicConsumer Class

Rom Cabral rom.t.cabral at gmail.com
Tue Sep 16 15:47:35 BST 2014

Hi guys,

I'm in the process of exploring RabbitMQ so my probIem might be very easy 
to some of you. Anyway, I decided to post this question after long hours of 
debugging my code. Basically, I have 2 problems that I noticed when I try 
extending DefaultConsumer. 

First is that, acknowledgement is not working, message is moved back from 
unacknowledge to ready upon closing the channel. Second is that I'm 
encountering "AlreadyClosedException" when trying to close the connection. 
I'm wonder why this is happening even if I have checking to close only open 
connection. Hope to hear your comments and suggestions.

class SampleConsumer : DefaultBasicConsumer

        public SampleConsumer(IModel channel) : base(channel)

        public override void HandleBasicDeliver(string consumerTag, ulong 
deliveryTag, bool redelivered, string exchange, string routingKey,
            IBasicProperties properties, byte[] body)
                Model.BasicAck(deliveryTag, false);
            catch (Exception e)
                Model.BasicNack(deliveryTag, false, false);
            //base.HandleBasicDeliver(consumerTag, deliveryTag, 
redelivered, exchange, routingKey, properties, body);

class Receiver : IDisposable
// create xchange, queue and binding here
public void Subscribe(string queue)
            var consumer = new SampleConsumer(Channel);
            Channel.BasicConsume(queue, false, consumer);

    public void Dispose()
            if (Channel != null && Channel.IsOpen)

            if (Connection != null && Connection.IsOpen)

  using(var r = new Receiver(server...)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20140916/fe29ace0/attachment.html>

More information about the rabbitmq-discuss mailing list