Пример #1
0
        void QueueReceiver()
        {
            if (_enabled == false)
            {
                return;
            }

            lock (_locker)
            {
                if (_receiverCount > 0)
                {
                    return;
                }

                if (_consumerCount >= _maximumThreadCount)
                {
                    return;
                }

//				if (_log.IsDebugEnabled)
//					_log.DebugFormat("Queueing receiver for {0}", _bus.Endpoint.Address.Uri);

                var context = new ServiceBusReceiveContext(_bus, _eventChannel, _receiveTimeout);

                Interlocked.Increment(ref _receiverCount);
                Interlocked.Increment(ref _consumerCount);

                try
                {
                    ThreadPool.QueueUserWorkItem(x => context.ReceiveFromEndpoint());
                }
                catch (Exception ex)
                {
                    _log.Error("Unable to queue consumer to thread pool", ex);

                    Interlocked.Decrement(ref _receiverCount);
                    Interlocked.Decrement(ref _consumerCount);
                }
            }

            _eventChannel.Send(new ReceiverQueued
            {
                ReceiverCount = _receiverCount,
                ConsumerCount = _consumerCount,
            });
        }
Пример #2
0
		void QueueReceiver()
		{
			if (_enabled == false)
				return;

			lock (_locker)
			{
				if (_receiverCount > 0)
					return;

				if (_consumerCount >= _maximumThreadCount)
					return;

				if (_log.IsDebugEnabled)
					_log.DebugFormat("Queueing receiver for {0}", _bus.Endpoint.Address.Uri);

				var context = new ServiceBusReceiveContext(_bus, _eventChannel, _receiveTimeout);

				Interlocked.Increment(ref _receiverCount);
				Interlocked.Increment(ref _consumerCount);

				try
				{
					ThreadPool.QueueUserWorkItem(x => context.ReceiveFromEndpoint());
				}
				catch (Exception ex)
				{
					_log.Error("Unable to queue consumer to thread pool", ex);

					Interlocked.Decrement(ref _receiverCount);
					Interlocked.Decrement(ref _consumerCount);
				}
			}

			_eventChannel.Send(new ReceiverQueued
				{
					ReceiverCount = _receiverCount,
					ConsumerCount = _consumerCount,
				});
		}