[rabbitmq-discuss] EndOfStreamException SharedQueue closed with .net client

Dex dhickey at gmail.com
Thu Mar 24 23:13:03 GMT 2011


Hi all,

new to RabbitMQ here :) Version 2.4.0, erlang 5.8.3, win7 x64, .Net 4

Learning the API, I've based the code below on the examples in the
dotnet client user guide.

When run, the Task thread will dequeue the message fine, but will
throw when starting to de-queue again:

System.IO.EndOfStreamException was unhandled by user code
  Message=SharedQueue closed
  Source=RabbitMQ.Client
  StackTrace:
       at RabbitMQ.Util.SharedQueue.EnsureIsOpen()
       at RabbitMQ.Util.SharedQueue.Dequeue()
       at RabbitMQTest.Program.<Main>b__0() in c:\dev\RabbitMQTest
\Program.cs:line 33
       at System.Threading.Tasks.Task.InnerInvoke()
       at System.Threading.Tasks.Task.Execute()
  InnerException:

Stepping through the program I notice that consumer.Queue.m_isOpen is
true just before the second Dequeue is attempted. Of course it's false
just after the exception is thrown.

Can anyone see anything wrong with my code? Any pointers would be
great.

Many thanks.

----------

using System;
using System.Text;
using System.Threading.Tasks;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using RabbitMQ.Client.Exceptions;

internal class Program
{
	private static void Main(string[] args)
	{
		const string exchangeName = "exchange";
		const string routingKey = "routingkey";

		Task.Factory.StartNew(() =>
		{
			const string consumerQueue = "consumer";
			IConnection consumerConnection = new
ConnectionFactory().CreateConnection();
			IModel consumerChannel = consumerConnection.CreateModel();
			consumerChannel.ExchangeDeclare(exchangeName, ExchangeType.Direct);
			consumerChannel.QueueDeclare(consumerQueue, false, false, false,
null);
			consumerChannel.QueueBind(consumerQueue, exchangeName, routingKey,
null);

			var consumer = new QueueingBasicConsumer(consumerChannel);
			consumerChannel.BasicConsume(consumerQueue, true, consumer);
			while (true)
			{
				try
				{
					// System.IO.EndOfStreamException ("SharedQueue closed") on
second dequeue
					var e = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
					byte[] body = e.Body;
					Console.WriteLine(Encoding.UTF8.GetString(body));
					consumerChannel.BasicAck(e.DeliveryTag, false);
				}
				catch (OperationInterruptedException ex)
				{
					break;
				}
			}
			consumerConnection.Close();
			consumerChannel.Close();
		});

		Console.WriteLine("Press enter to send message.");
		Console.ReadLine();

		IConnection producerConnection = new
ConnectionFactory().CreateConnection();
		IModel producerChannel = producerConnection.CreateModel();
		byte[] messageBodyBytes = Encoding.UTF8.GetBytes("Hello, world!");
		producerChannel.BasicPublish(exchangeName, routingKey, null,
messageBodyBytes);

		Console.ReadLine();
	}
}


More information about the rabbitmq-discuss mailing list