Пример #1
0
        public void Dispose()
        {
            _disposed = true;
            DisposeConsumerManager();

            //NOTE: Sometimes, disposing the channel blocks current thread
            var task = Task.Factory.StartNew(() => _createdChannels.ForEach(DisposeChannel), Global.DefaultTaskCreationOptionsProvider());

            task.ContinueWith(t => _createdChannels.Clear(), Global.DefaultTaskContinuationOptionsProvider())
            .Wait((int)Global.ConsumerDisposeTimeoutInSeconds * 1000);

            if (_connection.IsConnected)
            {
                _connection.Dispose();
            }
        }
Пример #2
0
        private void CloseTunnel()
        {
            if (_disposed)
            {
                return;
            }

            _autoResetEvent.WaitOne();
            try
            {
                if (_dedicatedPublishingChannel != null)
                {
                    _dedicatedPublishingChannel.BasicAcks   -= OnBrokerReceivedMessage;
                    _dedicatedPublishingChannel.BasicNacks  -= OnBrokerRejectedMessage;
                    _dedicatedPublishingChannel.BasicReturn -= OnMessageIsUnrouted;
                }

                _consumerManager.ClearConsumers();

                //NOTE: Sometimes, disposing the channel blocks current thread
                var task = Task.Factory.StartNew(() => _createdChannels.ForEach(DisposeChannel), Global.DefaultTaskCreationOptionsProvider());
                task.ContinueWith(t => _createdChannels.Clear(), Global.DefaultTaskContinuationOptionsProvider());

                if (OnClosed != null)
                {
                    OnClosed();
                }
            }
            finally
            {
                _autoResetEvent.Set();
            }
        }