[rabbitmq-discuss] .NET client SimpleRpcServer question

Ryan Davis ryan at acceleration.net
Tue Jun 9 20:05:01 BST 2009

Ryan Davis wrote:
> I'm going to add a flag and test out calling Close() from various points
> in HandleCall/HandleCast/ProcessRequest.
Wow, I really didn't think that one through. 
HandleCall/HandleCast/ProcessRequest are only called when there is a
message to process.  If there is no message to process, the
SimpleRpcServer is blocked on Subscription.Next(), and will never
exit.   My current test case starts a SimpleRpcServer, then tries to
stop it, without sending any messages.

I changed my code so if the SimpleRpcServer sees a certain byte[]
message (stored as ShutdownKey), it will close itself:

public override void HandleCast(bool isRedelivered, IBasicProperties
requestProperties, byte[] body)
  for (var i = 0; i < body.Length; i++) {
     if (body[i] != ShutdownKey[i]) return;
  Close(); //we must have matched, shut down.

As I expected, this throws a different exception:
System.InvalidOperationException: Operation is not valid due to the current state of the object.
   at RabbitMQ.Client.MessagePatterns.Subscription.Next() in d:\Projects\rabbitmq-dotnet-client-1.5.3\src\client\messagepatterns\Subscription.cs:line 323
   at RabbitMQ.Client.MessagePatterns.Subscription.System.Collections.IEnumerator.MoveNext() in d:\Projects\rabbitmq-dotnet-client-1.5.3\src\client\messagepatterns\Subscription.cs:line 437
   at RabbitMQ.Client.MessagePatterns.SimpleRpcServer.MainLoop() in d:\Projects\rabbitmq-dotnet-client-1.5.3\src\client\messagepatterns\SimpleRpcServer.cs:line 206

I'm going to start mucking about in SimpleRpcServer.cs/Subscription.cs
to see what's the smalled change I can make to fix it.


Ryan Davis
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