Exemple #1
0
        public IRabbitMqConnection GetConnection()
        {
            lock (_lock)
            {
                if (_availableConnections.TryDequeue(out var connection) && connection.IsOpen)
                {
                    return(connection);
                }

                connection?.Dispose();

                var factory      = CreateConnectionFactory();
                var connectionId = ConnectionId.New();

                connection = new RabbitMqConnection(connectionId, factory.CreateConnection(connectionId), this, _options);

                return(connection);
            }
        }
Exemple #2
0
        public void ReturnConnection(RabbitMqConnection connection, bool reRegisterForFinalization)
        {
            lock (_lock)
            {
                if (connection.IsOpen)
                {
                    if (reRegisterForFinalization)
                    {
                        GC.ReRegisterForFinalize(connection);
                    }

                    connection.Reset();

                    _availableConnections.Enqueue(connection);
                    return;
                }

                connection.UnderlyingConnection?.Dispose();
            }
        }