/// <summary>
        /// 关闭
        /// </summary>
        public override void Close()
        {
            if (channels.Count > 0)
            {
                foreach (IModel channel in channels)
                {
                    if (channel.IsOpen)
                    {
                        channel.Close();
                        channel.Dispose();
                    }
                }

                channels.Clear();
            }

            if (Status == ConnectionStatusType.OPENED)
            {
                connection.Close();
                connection.Dispose();
            }

            connection = null;

            OnClosed();
        }
예제 #2
0
 public void Close()
 {
     if (_connection.IsOpen)
     {
         _connection.Close();
     }
 }
        /// <summary>
        /// 执行关闭
        /// </summary>
        /// <returns>事件数据</returns>
        protected override object ExecClose()
        {
            if (channels.Count > 0)
            {
                foreach (IModel channel in channels)
                {
                    if (channel.IsOpen)
                    {
                        channel.Close();
                        channel.Dispose();
                    }
                }

                channels.Clear();
            }

            if (Status == ConnectionStatusType.OPENED)
            {
                connection.Close();
                connection.Dispose();
            }

            connection  = null;
            virtualPath = RabbitConnectionInfo.DEFAULT_VIRTUAL_PATH;

            return(null);
        }
예제 #4
0
 /// <summary>
 /// 销毁
 /// </summary>
 public override void Dispose()
 {
     _channel.Close();
     _logger.LogWarning("关闭RabbitMQ通道");
     _connection.Close();
     _logger.LogWarning("关闭RabbitMQ连接");
     base.Dispose();
 }
예제 #5
0
        /// <summary>
        /// 关闭
        /// </summary>
        public void Shutdown()
        {
            if (Interlocked.CompareExchange(ref _isRunning, 0, 1) == 1)
            {
                Thread.Sleep(100);
                if (_amqpConnection != null)
                {
                    if (_mode == ConsumeMode.Push)
                    {
                        foreach (var topic in _globalConsumers.Keys)
                        {
                            var consumers = _globalConsumers[topic];
                            foreach (var queueIndex in consumers.Keys)
                            {
                                var channel = consumers[queueIndex].Model;
                                if (channel.IsOpen)
                                {
                                    channel.Close(RabbitMQConstants.ConnectionForced, $"\"{topic}-{queueIndex}\"'s normal channel disposed");
                                }
                            }
                            consumers.Clear();
                        }
                        _globalConsumers.Clear();
                    }
                    else
                    {
                        foreach (var topic in _globalChannels.Keys)
                        {
                            var channels = _globalChannels[topic];
                            foreach (var queueIndex in channels.Keys)
                            {
                                var channel        = channels[queueIndex].Item1;
                                var consumerThread = channels[queueIndex].Item2;
                                if (channel.IsOpen)
                                {
                                    channel.Close(RabbitMQConstants.ConnectionForced, $"\"{topic}-{queueIndex}\"'s normal channel disposed");
                                }
                            }
                            channels.Clear();
                        }
                        _globalChannels.Clear();
                    }

                    if (_selfCreate)
                    {
                        _amqpConnection.Close();
                        _amqpConnection = null;
                    }
                }
            }
        }
예제 #6
0
        public void Close()
        {
            try
            {
                // _explicitlyClosed = true;

                // let the physical close time out if necessary
                _connection.Close(_closeTimeout);
            }
            catch (AlreadyClosedException)
            {
                // Ignore
            }
            catch (Exception e)
            {
                throw RabbitExceptionTranslator.ConvertRabbitAccessException(e);
            }
        }
예제 #7
0
 /// <summary>
 /// 关闭
 /// </summary>
 public void Shutdown()
 {
     if (Interlocked.CompareExchange(ref _isRunning, 0, 1) == 1)
     {
         _cleanIdleChannelTimer.Change(Timeout.Infinite, Timeout.Infinite);
         Thread.Sleep(100);
         while (_channelPool.TryDequeue(out Tuple <DateTime, IRabbitMQChannel> item))
         {
             if (item.Item2.IsOpen)
             {
                 item.Item2.Close();
             }
         }
         if (_amqpConnection != null)
         {
             if (_selfCreate)
             {
                 _amqpConnection.Close();
             }
             _amqpConnection = null;
         }
     }
 }
예제 #8
0
        /// <summary>
        /// 执行关闭
        /// </summary>
        /// <returns>事件数据</returns>
        protected override object ExecClose()
        {
            if (channels.Count > 0)
            {
                foreach (IModel channel in channels)
                {
                    if (channel.IsOpen)
                    {
                        channel.Close();
                        channel.Dispose();
                    }
                }

                channels.Clear();
            }

            if (Status == ConnectionStatusType.OPENED)
            {
                connection.Close();
                connection.Dispose();
            }

            return(null);
        }
예제 #9
0
        } // MakeNewConnection

        private void DestroyConnection(ref RmqCl.IConnection connection, ref RmqCl.IModel channel)
        {
            // This method disposes the AMQP-connection-related object

            try
            {
                if (channel != null)
                {
                    if (m_messageConsumer != null)
                    {
                        m_messageConsumer.Received -= MessageReceived;
                    }

                    try
                    {
                        channel.ModelShutdown -= ModelShutdown;
                        channel.Close();
                    }
                    catch { }
                    channel.Dispose();
                    channel = null;
                }

                if (connection != null)
                {
                    try
                    {
                        connection.Close();
                    }
                    catch { }
                    connection.Dispose();
                    connection = null;
                }
            }
            catch {}
        } // DestroyConnection