Erlang/OTP Forums

Author Message

<  RabbitMQ mailing list  ~  .NET Client Library Shared Queue Closed Error on Subscriptio

Guest
Posted: Sun Mar 30, 2008 9:26 am Reply with quote
Guest
Please can you help me with the following error. Using the examples that come with the .NET Cllient Library I have written a small program that creates a subscription and reads any published messages in the queue. The code works and reads any messages in the queue, however when there are no more messages left to read in the Queue or when you run the program without any messages in the queue (i.e. when the queue is empty) the connection simply closes and throws the following EndOfStreamException:

System.IO.EndOfStreamException: SharedQueue closed
at RabbitMQ.Util.SharedQueue.EnsureIsOpen()
at RabbitMQ.Util.SharedQueue.Dequeue()
at ConsoleApplication2.Program.Main(String[] args) in C:\rabbitmqdotnet\testw
indowsapp\ConsoleApplication2\ConsoleApplication2\Program.cs:line 47

Here is a listing of the source code. Thanks for all your help.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RabbitMQ.Client;
using System.IO;
using RabbitMQ.Client.Content;
using RabbitMQ.Client.Events;
using RabbitMQ.Client.MessagePatterns;
using RabbitMQ.Util;


namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{

IProtocol protocol = Protocols.FromConfiguration("my-protocol");
string hostName = "10.10.10.25";
int portNumber = 5678;
string exchangeName = "testexchange";
string queueName = "testqueue";
string routingKey = "routingkey";
ConnectionFactory factory = new ConnectionFactory();
IConnection conn = factory.CreateConnection(protocol, hostName, portNumber);
IModel channel = conn.CreateModel();
string realm = "/data";
ushort ticket = channel.AccessRequest(realm);
channel.ExchangeDeclare(ticket, exchangeName, ExchangeType.Direct);
channel.QueueDeclare(ticket, queueName);
channel.QueueBind(ticket, queueName, exchangeName, routingKey, false, null);

QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);
channel.BasicConsume(ticket, queueName, null, consumer);
Console.WriteLine("Entering Loop .. Please press Control C to exit");
while (true)
{
try
{

else
{
RabbitMQ.Client.Events.BasicDeliverEventArgs e2 =
(RabbitMQ.Client.Events.BasicDeliverEventArgs)consumer.Queue.Dequeue();
IBasicProperties props = e2.BasicProperties;
byte[] body = e2.Body;

string str = System.Text.Encoding.UTF8.GetString(body);

Console.WriteLine(str);
channel.BasicAck(e2.DeliveryTag, false);
}
}
catch (EndOfStreamException ex)
{
// The consumer was removed, either through
// channel or connection closure, or through the
// action of IModel.BasicCancel().

Console.WriteLine(ex.ToString());
break;
}
}
}
}
}





_______________________________________________
rabbitmq-discuss mailing list
rabbitmq-discuss@lists.rabbitmq.com
http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
Post recived from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum