Quantcast

Problem Extending DefaultBasicConsumer Class

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Problem Extending DefaultBasicConsumer Class

Rom Cabral
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)
        {
            try
            {
                Console.WriteLine(Encoding.ASCII.GetString(body));
                Model.BasicAck(deliveryTag, false);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                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)
                Channel.Close();

            if (Connection != null && Connection.IsOpen)
                Connection.Close();
        }
}

Main
  using(var r = new Receiver(server...)
     r.Subscribe(queue);

_______________________________________________
rabbitmq-discuss mailing list has moved to https://groups.google.com/forum/#!forum/rabbitmq-users,
please subscribe to the new list!

[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem Extending DefaultBasicConsumer Class

Michael Klishin-4
Rom,

This list has been deprecated in late July. We've announced that it will be
discontinued on Oct 1st in August. We are 2 weeks away from that, time to
start posting new questions to the new list, rabbitmq-users:

https://groups.google.com/forum/#!forum/rabbitmq-users

On 16 September 2014 at 18:49:42, Rom Cabral ([hidden email]) wrote:
> First is that, acknowledgement is not working, message is moved  
> back from unacknowledge to ready upon closing the channel.

This is by design. Closing channel or connection or when connection goes
away all result in unacknowledged messages being re-queued. Acknowledgements
would not make much sense otherwise.

┬á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

Something tries to use a channel after it is closed. Please see your stack trace
to figure out what it may be.
--  
MK  

Staff Software Engineer, Pivotal/RabbitMQ
_______________________________________________
rabbitmq-discuss mailing list has moved to https://groups.google.com/forum/#!forum/rabbitmq-users,
please subscribe to the new list!

[hidden email]
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Loading...