Yes, I agree that this is the main drawback of current RabbitMQ client implementations. I have been using RMQ for about 2 years (.NET library), and a lot has changed during this time. It should be completely rewritten from scratch, and I just did not have time to do it.
But I have some pointers. First, I would create a wrapper class for your connection / channel object (you need a channel to perform AMQP operations, the only thing the connection is used for is creating channels). Then your wrapper class can keep track of whether the channel or connection is open, and act accordingly.
My code is as follows:
while (_iNeedToBeSendingAndReceiving) { try { //This blocks indefinitely while waiting for a connection. using (var channel = ConnectionWrapper.CreateChannel(string connectionString) { //Do stuff, blah, blah //When the connection or channel closes, an exception is thrown and //I move to the catch block. } catch(ConnectionInterruptException ex) { //Eat, yummy! } }
My possible plan is to distract even this material and create a completely new way of interacting with the RabbitMQ library (or any other). I will let you know when I do some work on this issue, it may be in a couple of months.
theMayer
source share