<div dir="ltr"><div>Hi guys,</div><div><br></div><div>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. </div><div><br></div><div>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.</div><div><br></div><div>class SampleConsumer : DefaultBasicConsumer</div><div>    {</div><div><br></div><div>        public SampleConsumer(IModel channel) : base(channel)</div><div>        {</div><div>        }</div><div><br></div><div>        public override void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey,</div><div>            IBasicProperties properties, byte[] body)</div><div>        {</div><div>            try</div><div>            {</div><div>                Console.WriteLine(Encoding.ASCII.GetString(body));</div><div>                Model.BasicAck(deliveryTag, false);</div><div>            }</div><div>            catch (Exception e)</div><div>            {</div><div>                Console.WriteLine(e.Message);</div><div>                Model.BasicNack(deliveryTag, false, false);</div><div>                </div><div>            }</div><div>            //base.HandleBasicDeliver(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body);</div><div>        }</div><div>    }</div><div>}</div><div><br></div><div>class Receiver : IDisposable</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre">             </span>// create xchange, queue and binding here</div><div><span class="Apple-tab-span" style="white-space:pre">            </span>public void Subscribe(string queue)</div><div>        {</div><div>            var consumer = new SampleConsumer(Channel);</div><div>            Channel.BasicConsume(queue, false, consumer);</div><div>        }</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">       </span>    public void Dispose()</div><div>        {</div><div>            if (Channel != null && Channel.IsOpen)</div><div>                Channel.Close();</div><div><br></div><div>            if (Connection != null && Connection.IsOpen)</div><div>                Connection.Close();</div><div>        }</div><div>}</div><div><br></div><div>Main</div><div>  using(var r = new Receiver(server...)</div><div>     r.Subscribe(queue);</div></div>