<html><head>
<meta http-equiv="content-type" content="text/html; charset=us-ascii">
<title>Re: Fault-tolerant subscriptions using the .NET client</title>
</head><body>Hi again,<br>
<br>
After
a bit of investigation and information from a friend, I went down the path
of periodically checking the IsOpen property on the Connection object. If
false, then I go through the process of attempting to re-establish the
connection.<br>
<br>
Is this a valid approach? Is it the recommended approach?<br>
<br>
Many thanks<br>
OJ<br>
<br>
<br>
<div class="gmail_quote">On 25 March 2011 20:36, OJ Reeves <span dir="ltr"
><oj@buffered.io></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px
#ccc solid;padding-left:1ex;">
<div>Greetings Rabbiters,<br>
<br>
I'm
currently working on a system which is using RabbitMQ as the hub of message
transfers. One of the scenarios we are using it for is to funnel masses of
data from the web into an SQL database. The messages are passed to the
queues via an Erlang web application. We have a series of .NET services
running which are subscribed to the queues and they take the messages as
they come in and write them to an MS SQL back-end.<br>
<br>
What I would like
to do is handle the case where the connection between RabbitMQ and the
subscriber is broken for some reason but something other than the .NET
client terminating the connection. For example, if RabbitMQ is stopped
manually, a netsplit happens, etc. I want the .NET client to know that there
has been a connection failure so that the connection and subscription can
be reestablished.<br>
<br>
In my .NET code, I do something like the following to get the connection
set up:<br>
<br>
ConnectionFactory cf = ...;<br>
var conn = cf.CreateConnection();<br>
var model = conn.CreateModel();<br>
model.ExchangeDeclare(<wbr>exchange, exchangeType);<br>
model.QueueDeclare(queueName);<br>
model.QueueBind(queueName, exchange, routeKey, false, null);<br>
var subscription = new Subscription(model, queueName);<br>
<br>
I then have a worker thread which essentially does the following (over and
over):<br>
<br>
        private BasicDeliverEventArgs
GetNextMessage()<br>
        {<br>
            var
eventArgs = default(BasicDeliverEventArgs)<wbr>;<br>
            if
(!subscripion.Next(500, out eventArgs))<br>
            {<br>
           <span title="s
t"></span> <span title="s
t"></span>    eventArgs = null;<br>
            }<br>
            return
eventArgs;<br>
        }<br>
<br>
When
a valid eventArgs instance is returned, the message is processed. Otherwise
it a few other things. The reason it's doing this is so that if the service
is paused using the service manager, then the code has the chance to stop
looking for messages. When restarted, this GetNextMessage() is then called
again a loop. There are other things that the thread might need to do as
well, but that's basically the gist of it.<br>
<br>
So at this point, all is well. Everything works just fine and the messages
come through nicely (and insanely quick to boot).<br>
<br>
If
I simulate a network issue by stopping the RabbitMQ server, the subscriber
is not informed about the connection loss. Even if the worker thread
continues polling the subscription, no errors are reported at all. The only
time an error is indicated is when the connection is closed (an IOException
is thrown). Obviously this isn't helpful because until we attempt to close
the service down we assume that the connection is up and hence wouldn't have
any indication that there are connectivity issues.<br>
<br>
What I would like
to do is put something in place which is able to detect a connection
failure and get things working again. I was wondering if anyone had any
insights into the best way to approach this problem. Is there something in
the .NET client that I am not configuring properly to enable certain
behaviours? Should I have something else running which is checking to see if
it can establish connections and hence detect issues that way?<br>
<br>
What's the best approach?<br>
<br>
Many thanks for your time.<br>
Best regards<br>
OJ<br>
<font color="#888888">
<br clear="all">
<br>
-- <br>
<br>
OJ Reeves<br>
<a href="http://buffered.io/" target="_blank">http://buffered.io/</a><br>
</font></div>
Greetings Rabbiters,<br>
<br>
I'm
currently working on a system which is using RabbitMQ as the hub of message
transfers. One of the scenarios we are using it for is to funnel masses of
data from the web into an SQL database. The messages are passed to the
queues via an Erlang web application. We have a series of .NET services
running which are subscribed to the queues and they take the messages as
they come in and write them to an MS SQL back-end.<br>
<br>
What I would like
to do is handle the case where the connection between RabbitMQ and the
subscriber is broken for some reason but something other than the .NET
client terminating the connection. For example, if RabbitMQ is stopped
manually, a netsplit happens, etc. I want the .NET client to know that there
has been a connection failure so that the connection and subscription can
be reestablished.<br>
<br>
In my .NET code, I do something like the following to get the connection
set up:<br>
<br>
ConnectionFactory cf = ...;<br>
var conn = cf.CreateConnection();<br>
var model = conn.CreateModel();<br>
model.ExchangeDeclare(exchange, exchangeType);<br>
model.QueueDeclare(queueName);<br>
model.QueueBind(queueName, exchange, routeKey, false, null);<br>
var subscription = new Subscription(model, queueName);<br>
<br>
I then have a worker thread which essentially does the following (over and
over):<br>
<br>
        private BasicDeliverEventArgs
GetNextMessage()<br>
        {<br>
            var
eventArgs = default(BasicDeliverEventArgs);<br>
            if
(!subscripion.Next(500, out eventArgs))<br>
            {<br>
           <span title="s
t"></span> <span title="s
t"></span>    eventArgs = null;<br>
            }<br>
            return
eventArgs;<br>
        }<br>
<br>
When
a valid eventArgs instance is returned, the message is processed. Otherwise
it a few other things. The reason it's doing this is so that if the service
is paused using the service manager, then the code has the chance to stop
looking for messages. When restarted, this GetNextMessage() is then called
again a loop. There are other things that the thread might need to do as
well, but that's basically the gist of it.<br>
<br>
So at this point, all is well. Everything works just fine and the messages
come through nicely (and insanely quick to boot).<br>
<br>
If
I simulate a network issue by stopping the RabbitMQ server, the subscriber
is not informed about the connection loss. Even if the worker thread
continues polling the subscription, no errors are reported at all. The only
time an error is indicated is when the connection is closed (an IOException
is thrown). Obviously this isn't helpful because until we attempt to close
the service down we assume that the connection is up and hence wouldn't have
any indication that there are connectivity issues.<br>
<br>
What I would like
to do is put something in place which is able to detect a connection
failure and get things working again. I was wondering if anyone had any
insights into the best way to approach this problem. Is there something in
the .NET client that I am not configuring properly to enable certain
behaviours? Should I have something else running which is checking to see if
it can establish connections and hence detect issues that way?<br>
<br>
What's the best approach?<br>
<br>
Many thanks for your time.<br>
Best regards<br>
OJ<br>
<br clear="all">
<br>
-- <br>
<br>
OJ Reeves<br>
http://buffered.io/<br>
</blockquote>
</div>
<br>
<br clear="all">
<br>
-- <br>
<br>
OJ Reeves<br>
http://buffered.io/<br>
</body></html>