Beispiel #1
0
 public RabbitMQBrokerConnection CreateModel()
 {
     try
     {
         var model = GetConnection().CreateModel();
         return(RabbitMQBrokerConnection.ConnectionSuccess(_options.HostName, model, _options));
     }
     catch (Exception e)
     {
         _logger.LogError(e, "RabbitMQ channel model create failed!");
         Console.WriteLine(e);
         throw;
     }
 }
Beispiel #2
0
        public bool ReturnModel(RabbitMQBrokerConnection rabbitConnection)
        {
            var rbtModel = rabbitConnection.RabbitMQModel;

            if (Interlocked.Increment(ref _count) <= _maxSize && rbtModel.IsOpen)
            {
                _pool.Enqueue(rbtModel);

                return(true);
            }

            Interlocked.Decrement(ref _count);

            Debug.Assert(_maxSize == 0 || _pool.Count <= _maxSize);

            return(false);
        }
Beispiel #3
0
        public bool BreakModel(RabbitMQBrokerConnection rabbitConnection)
        {
            if (rabbitConnection.IsClosed)
            {
                return(true);
            }

            try
            {
                var rbtModel = rabbitConnection.RabbitMQModel;
                rbtModel.Close();
                rbtModel.Dispose();

                return(true);
            }
            catch
            {
                return(rabbitConnection.IsClosed);
            }
        }
Beispiel #4
0
        private RabbitMQBrokerConnection RentModelInternal()
        {
            if (_pool.TryDequeue(out var model))
            {
                Interlocked.Decrement(ref _count);

                Debug.Assert(_count >= 0);

                return(RabbitMQBrokerConnection.ConnectionSuccess(_options.HostName, model, _options));
            }

            try
            {
                model = GetConnection().CreateModel();
            }
            catch (Exception e)
            {
                _logger.LogError(e, "RabbitMQ channel model create failed!");
                Console.WriteLine(e);
                throw;
            }

            return(RabbitMQBrokerConnection.ConnectionSuccess(_options.HostName, model, _options));
        }