6footunder
6footunder

Reputation: 1358

RabbitMQ with manual ack throwing "Shared Queue Closed"

The consumer code below (not too far removed from the worker sample) throws System.IO.EndOfStreamException ("SharedQueue closed") after a couple of iterations of a single message being nacked.

public void Consume ()
            {
                using (var connection = connectionFactory.CreateConnection ()) {
                    using (var channel = connection.CreateModel ()) {

                        channel.QueueDeclare (queueName, true, false, false, null);

                        // 0= “Dont send me a new message untill I’ve finshed”,  
                        // 1= “Send me one message at a time”
                        channel.BasicQos (0, 1, false);
                        var consumer = new QueueingBasicConsumer (channel);
                        channel.BasicConsume (queueName, false, consumer);

                        Console.WriteLine (" [*] Waiting for messages. " +
                        "To exit press CTRL+C");

                        while (true) {
                            BasicDeliverEventArgs ea;
                            try {
                                // block until a message can be dequeue
                                ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue ();

                                var body = ea.Body;
                                Console.WriteLine (" [x] Received, executing");

                                T thing = messageSerializer.Deserialize<T> (body);

                                try {
                                    executor.DynamicInvoke (thing);
                                } catch {
                                        channel.BasicNack (ea.DeliveryTag, false, true);
                                    }
                                }

                                channel.BasicAck (ea.DeliveryTag, false);
                            } catch (OperationCanceledException) {
                                logger.Error ("Bugger");
                            }
                        }
                    }
                }

I've read a few google results but AKAIK this typically happens when the stream has been closed due to manually acking when auto ack is set?

Thanks in advance.

Upvotes: 3

Views: 2354

Answers (2)

yohait
yohait

Reputation: 21

This Exception is thrown when the channel is closed. It's happening to me too only when I am debuging my code after a couple of messages So my guess is that we are getting timeout to the channel after a while. Check your Rabbit configurations

Upvotes: 0

6footunder
6footunder

Reputation: 1358

Doh!. I guess I'll leave this question in place in the rare event anybody else is as stupid as I am. Note in the code above that the BasicNack will occur and execution will then continue on to the Nack operation. This is the (obvious) cause of the issue. I need spanking.

Upvotes: 2

Related Questions