RabbitMQ c# System.IO.EndOfStreamException
c#, rabbitmq
Solution
The consumer is tied to the channel:
var consumer = new QueueingBasicConsumer(channel);
So if the channel has closed, then the consumer will not be able to fetch any additional events once the local `Queue` has been cleared.
Check for the channel to be open with
channel.IsOpen == true
and that the Queue has available events with
if( consumer.Queue.Count() > 0 )
before calling:
BasicDeliverEventArgs e = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
To be more specific, I would check the following before calling `Dequeue()`
if( !channel.IsOpen || !connection.IsOpen )
{
Your_Connection_Channel_Init_Function();
consumer = new QueueingBasicConsumer(channel); // consumer is tied to channel
}
if( consumer.Queue.Any() )
BasicDeliverEventArgs e = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
Problem
I get the following exception when a consumer is blocking to receive a message from the SharedQueue: ``` Unhandled Exception: System.IO.EndOfStreamException: SharedQueue closed at RabbitMQ.Util.SharedQueue.EnsureIsOpen() at RabbitMQ.Util.SharedQueue.Dequeue() at Consumer.Program.Main(String[] args) in c:\Users\pdecker\Documents\Visual Studio 2012\Projects\RabbitMQTest1\Consumer\Program.cs:line 33 ``` Here is the line of code that is being executed when the exception is thrown: ``` BasicDeliverEventArgs e = (BasicDeliverEventArgs)consumer.Queue.Dequeue(); ``` So far I have seen the exception occuring when rabbitMQ is inactive. Our application needs to have the consumer always connected and listening for keystrokes. Does anyone know the cause of this problem? Does anyone know how to recover from this problem? Thanks in advance.