Channel closed after BasicACK

1,494 views
Skip to first unread message

rommel...@meltwater.com

unread,
Mar 9, 2015, 11:00:16 AM3/9/15
to rabbitm...@googlegroups.com
I have a basic consumer, on the handleDelivery i send basicAck and on the next messaged an get an error saying that that channel is closed, how can i fix this? probably i'm using the Consumers the wrong way.

thanks.

Alvaro Videla

unread,
Mar 9, 2015, 11:04:08 AM3/9/15
to rommel...@meltwater.com, rabbitm...@googlegroups.com
Is better to post some sample code and perhaps error logs from the server. The error received at the client side would also be helpful.

Nonetheless, usually when a channel is closed due to a basicAck it might mean that your app is sending the wrong delivery_tag back to the server. Are you perhaps sharing channels across threads?
On Mon, Mar 9, 2015 at 4:00 PM <rommel...@meltwater.com> wrote:
I have a basic consumer, on the handleDelivery i send basicAck and on the next messaged an get an error saying that that channel is closed, how can i fix this? probably i'm using the Consumers the wrong way.

thanks.

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

rommel...@meltwater.com

unread,
Mar 9, 2015, 11:08:35 AM3/9/15
to rabbitm...@googlegroups.com, rommel...@meltwater.com
this is my class consumer:









package com.company.masf.search.consumer;




import java.io.IOException;




import org.apache.commons.logging.Log;


import org.apache.commons.logging.LogFactory;





import com.rabbitmq.client.AMQP;


import com.rabbitmq.client.Channel;


import com.rabbitmq.client.Envelope;


import com.rabbitmq.client.QueueingConsumer;


import com.rabbitmq.client.ShutdownSignalException;


import com.rabbitmq.client.impl.LongStringHelper;




public class DeleteSearchConsumer extends QueueingConsumer {


        Log LOG = LogFactory.getLog(DeleteSearchConsumer.class);




        public DeleteSearchConsumer(Channel channel) {


                super(channel);


        }




        @Override


        public void handleDelivery(java.lang.String consumerTag,


            Envelope envelope,


            AMQP.BasicProperties properties,


            byte[] body) throws IOException  {


                LOG.info("We got a message: "+ body.toString());


               


                SavedSearch search = null;


                Channel channel = getChannel();


                Long savedSearchId = getSavedSearchLong(body);




                LOG.info("properties" + properties);


                LOG.info("body" + body);




                channel.basicAck(envelope.getDeliveryTag(), false);


               


           


        }


       


        @Override


        public void handleShutdownSignal(java.lang.String consumerTag,


                        ShutdownSignalException sig) {


                LOG.info("Channel closed", sig);


        }




        private Long getSavedSearchLong(byte[] searchId) {


                String searchIdLongString = LongStringHelper.asLongString(searchId).toString();


                Long searchIdLong = Long.parseLong(searchIdLongString);        


               


                return searchIdLong;


        }


}


and this is the error:

2015-03-09 10:30:35 DeleteSearchConsumer [INFO ] [pool-2-thread-9]: body[B@5ccd5dc2

com.rabbitmq.client.AlreadyClosedException: channel is already closed due to channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - unknown delivery tag 1, class-id=60, method-id=80)


        at com.rabbitmq.client.impl.AMQChannel.ensureIsOpen(AMQChannel.java:190)


        at com.rabbitmq.client.impl.AMQChannel.transmit(AMQChannel.java:291)


        at com.rabbitmq.client.impl.AMQChannel.transmit(AMQChannel.java:285)


        at com.rabbitmq.client.impl.ChannelN.basicAck(ChannelN.java:1012)


        at com.bla.masf.search.consumer.DeleteSearchConsumer.handleDelivery(DeleteSearchConsumer.java:37)


        at com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:144)


        at com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:95)


        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)


        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)


        at java.lang.Thread.run(Thread.java:745)

Alvaro Videla

unread,
Mar 9, 2015, 11:53:57 AM3/9/15
to rommel...@meltwater.com, rabbitm...@googlegroups.com
Are you sharing the channel across many instances of your consumer?

Simon MacMullen

unread,
Mar 9, 2015, 11:59:56 AM3/9/15
to rommel...@meltwater.com, rabbitm...@googlegroups.com
On 09/03/15 15:08, rommel...@meltwater.com wrote:
> com.rabbitmq.client.AlreadyClosedException:channel isalready closed due
> to channel error;protocol method:#method<channel.close>(reply-code=406,
> reply-text=PRECONDITION_FAILED - unknown delivery tag 1

So either you have some threading related confusion as Alvaro suggested,
or you are acking messages delivered in no-ack mode.

Either way, you acked message #1 when the server thought it was not
unacknowledged.

Cheers, Simon

Michael Klishin

unread,
Mar 9, 2015, 3:11:26 PM3/9/15
to rabbitm...@googlegroups.com, Simon MacMullen, rommel...@meltwater.com
On 9 March 2015 at 18:59:57, Simon MacMullen (si...@rabbitmq.com) wrote:
> So either you have some threading related confusion as Alvaro
> suggested,
> or you are acking messages delivered in no-ack mode.
>
> Either way, you acked message #1 when the server thought it was
> not
> unacknowledged.

or the  ack was sent not on the channel the delivery was on.
--
MK

Staff Software Engineer, Pivotal/RabbitMQ
Reply all
Reply to author
Forward
0 new messages