[rabbitmq-discuss] RabbitMQ .NET client 3.2.3 bug?

Jonathan Holland joneholland at gmail.com
Mon Feb 24 15:50:40 GMT 2014


There is a ConnectionShutdown event you can subscribe to.

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:

public class RabbitConnectionManager
    {
        private readonly ConnectionFactory connectionFactory;
        private Lazy<IConnection> connection;

        public RabbitConnectionManager(Uri connectionString)
        {
            this.connectionFactory = new ConnectionFactory { Uri =
connectionString.AbsoluteUri, RequestedHeartbeat = 5 };
            this.connection = new Lazy<IConnection>(CreateConnection);

        }

        public IModel GetChannel()
        {
            return this.connection.Value.CreateModel();
        }

        public void Shutdown()
        {
            this.connection.Value.ConnectionShutdown -=
OnConnectionShutDown;
            this.connection.Value.Close();
        }

        private IConnection CreateConnection()
        {
            var conn = this.connectionFactory.CreateConnection();
            conn.ConnectionShutdown += this.OnConnectionShutDown;

            return conn;
        }

        private void OnConnectionShutDown(IConnection connection,
ShutdownEventArgs reason)
        {
            // If the connection is aborted, reinit the lazy connection so
that next access will reconnect.
            this.connection = new Lazy<IConnection>(CreateConnection);
        }
    }


On Mon, Feb 24, 2014 at 7:21 AM, Steve T <ssteo at roboqa.com> wrote:

> 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 ?
>
> Thanks,
> Steve
>
>
> On Mon, Feb 24, 2014 at 11:45 AM, Michael Klishin <mklishin at gopivotal.com>wrote:
>
>>
>> On 23 Feb 2014, at 17:51, Steve T <ssteo at roboqa.com> wrote:
>>
>> > 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();
>> >
>> >
>> > Stack Trace:
>> > System.Net.Sockets.SocketException: The descriptor is not a socket
>> >   at System.Net.Sockets.Socket.SetSocketOption (SocketOptionLevel
>> optionLevel, SocketOptionName optionName, Int32 optionValue)
>> >   at System.Net.Sockets.TcpClient.set_ReceiveTimeout (Int32 value)
>> >   at RabbitMQ.Client.Impl.SocketFrameHandler_0_9.set_Timeout (Int32
>> value)
>> >   at RabbitMQ.Client.Impl.ConnectionBase.ClosingLoop ()
>>
>> This is a known problem. Like Jonathan suggests, you will largely avoid
>> it by not connecting
>> every time you want to publish a message. RabbitMQ client connections are
>> supposed to
>> be long lived.
>>
>> MK
>>
>> Software Engineer, Pivotal/RabbitMQ
>>
>>
>> _______________________________________________
>> rabbitmq-discuss mailing list
>> rabbitmq-discuss at lists.rabbitmq.com
>> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>>
>
>
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20140224/698cb962/attachment.html>


More information about the rabbitmq-discuss mailing list