<div dir="ltr">There is a ConnectionShutdown event you can subscribe to.<div><br></div><div>The basic tenant is, share the connection across everything, but never share the channel. I usually abstract accessing a channel into a class that manages the connection lifecycle. An example:</div>
<div><br></div><div><div>public class RabbitConnectionManager</div><div>� � {</div><div>� � � � private readonly ConnectionFactory connectionFactory; � � � �</div><div>� � � � private Lazy<IConnection> connection;</div>
<div><br></div><div>� � � � public RabbitConnectionManager(Uri connectionString)</div><div>� � � � { � � � � � �</div><div>� � � � � � this.connectionFactory = new ConnectionFactory { Uri = connectionString.AbsoluteUri, RequestedHeartbeat = 5 };</div>
<div>� � � � � � this.connection = new Lazy<IConnection>(CreateConnection); � � � � � � � � � � � �</div><div>� � � � }</div><div><br></div><div>� � � � public IModel GetChannel()</div><div>� � � � {</div><div>� � � � � � return this.connection.Value.CreateModel();</div>
<div>� � � � }</div><div><br></div><div>� � � � public void Shutdown()</div><div>� � � � {</div><div>� � � � � � this.connection.Value.ConnectionShutdown -= OnConnectionShutDown;</div><div>� � � � � � this.connection.Value.Close();</div>
<div>� � � � }</div><div><br></div><div>� � � � private IConnection CreateConnection()</div><div>� � � � {</div><div>� � � � � � var conn = this.connectionFactory.CreateConnection();</div><div>� � � � � � conn.ConnectionShutdown += this.OnConnectionShutDown;</div>
<div><br></div><div>� � � � � � return conn;</div><div>� � � � }</div><div><br></div><div>� � � � private void OnConnectionShutDown(IConnection connection, ShutdownEventArgs reason)</div><div>� � � � {</div><div>� � � � � � // If the connection is aborted, reinit the lazy connection so that next access will reconnect.</div>
<div>� � � � � � this.connection = new Lazy<IConnection>(CreateConnection);</div><div>� � � � }</div><div>� � }</div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Feb 24, 2014 at 7:21 AM, Steve T <span dir="ltr"><<a href="mailto:ssteo@roboqa.com" target="_blank">ssteo@roboqa.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Ok, thanks. Is there any property or method in the RabbitMQ .NET client that allows me to check if the connection is still alive? Let's say if RabbitMQ server got restarted, etc. how do I recreate my connection ?<div>

<br></div><div>Thanks,</div><div>Steve</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Feb 24, 2014 at 11:45 AM, Michael Klishin <span dir="ltr"><<a href="mailto:mklishin@gopivotal.com" target="_blank">mklishin@gopivotal.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
On 23 Feb 2014, at 17:51, Steve T <<a href="mailto:ssteo@roboqa.com" target="_blank">ssteo@roboqa.com</a>> wrote:<br>
<br>
> I'm using RabbitMQ .NET client 3.2.3 with RabbitMQ 3.2.3 but encountering some random errors thrown from within the client itself. The error below happens very occassionally during item publishing via my own function EnqueueItem();<br>


><br>
><br>
> Stack Trace:<br>
> System.Net.Sockets.SocketException: The descriptor is not a socket<br>
> � at System.Net.Sockets.Socket.SetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, Int32 optionValue)<br>
> � at System.Net.Sockets.TcpClient.set_ReceiveTimeout (Int32 value)<br>
> � at RabbitMQ.Client.Impl.SocketFrameHandler_0_9.set_Timeout (Int32 value)<br>
> � at RabbitMQ.Client.Impl.ConnectionBase.ClosingLoop ()<br>
<br>
This is a known problem. Like Jonathan suggests, you will largely avoid it by not connecting<br>
every time you want to publish a message. RabbitMQ client connections are supposed to<br>
be long lived.<br>
<br>
MK<br>
<br>
Software Engineer, Pivotal/RabbitMQ<br>
<br>
<br>
_______________________________________________<br>
rabbitmq-discuss mailing list<br>
<a href="mailto:rabbitmq-discuss@lists.rabbitmq.com" target="_blank">rabbitmq-discuss@lists.rabbitmq.com</a><br>
<a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a><br>
</blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
rabbitmq-discuss mailing list<br>
<a href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss@lists.rabbitmq.com</a><br>
<a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a><br>
<br></blockquote></div><br></div>