[rabbitmq-discuss] .NET client SimpleRpcServer question

Ryan Davis ryan at acceleration.net
Fri Jun 5 15:20:08 BST 2009


I have some C# code extending SimpleRpcServer and am getting an
exception when trying to shut down.  In the documentation PDF, it said
to call the Close() function on your RpcServer when you are ready to
shutdown.  Since the MainLoop() function blocks, the Close() has to be
called from another thread, right?  I have code that looks something
like this:

//RpcServer is a member variable
parentObj.ShuttingDown += delegate {
  RpcServer.Close();
};
// glossing over the AMQP config a little here
using(var connection =  factory.CreateConnection("my-amqp-server"))
using(var model =  connection.CreateModel())
using(var subscription =  new Subscription(model, "queue", false))
using (RpcServer = new MyRpcServer(subscription, this)) { // MyRpcServer
extends SimpleRpcServer
  RpcServer.MainLoop();
}

When I do fire the ShuttingDown event from another thread, we call
Close() with no problems, and then the MainLoop throws a
NullReferenceException:

System.NullReferenceException: Object reference not set to an instance of an object.     
at RabbitMQ.Client.Impl.ModelBase.BasicCancel(String consumerTag)     
at RabbitMQ.Client.MessagePatterns.Subscription.Close()     
at RabbitMQ.Client.MessagePatterns.Subscription.System.IDisposable.Dispose()     
at RabbitMQ.Client.MessagePatterns.SimpleRpcServer.MainLoop()

I followed this call stack through the RabbitMQ.Client source and didn't
see anything obvious.

This isn't causing me any harm right now (other than red flags in my
logs), but it would be if I tried to put anything important after the
MainLoop call.

Is there a cleaner way to shut down an RpcServer?  Should I just swallow
this nullref when I'm shutting down?

Thanks,

-- 
Ryan Davis
Acceleration.net
Director of Programming Services
2831 NW 41st street, suite B
Gainesville, FL 32606

Office: 352-335-6500 x 124
Fax: 352-335-6506





More information about the rabbitmq-discuss mailing list