Exemple #1
0
    protected virtual void Consume()
    {
        Consumer = ConsumerPool.Get(GroupId, ConnectionName);

        Task.Factory.StartNew(async() =>
        {
            Consumer.Subscribe(TopicName);

            while (true)
            {
                try
                {
                    var consumeResult = Consumer.Consume();

                    if (consumeResult.IsPartitionEOF)
                    {
                        continue;
                    }

                    await HandleIncomingMessage(consumeResult);
                }
                catch (ConsumeException ex)
                {
                    Logger.LogException(ex, LogLevel.Warning);
                    await ExceptionNotifier.NotifyAsync(ex, logLevel: LogLevel.Warning);
                }
            }
        }, TaskCreationOptions.LongRunning);
    }
Exemple #2
0
        public void Start()
        {
            if (_started)
            {
                return;
            }

            try
            {
                _serviceContainer.Start();

                _consumerPool = new ThreadPoolConsumerPool(this, _eventChannel, _receiveTimeout)
                {
                    MaximumConsumerCount = MaximumConsumerThreads,
                };
                _consumerPool.Start();
            }
            catch (Exception)
            {
                if (_consumerPool != null)
                {
                    _consumerPool.Dispose();
                }

                throw;
            }

            _started = true;
        }
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }
            if (disposing)
            {
                if (_consumerPool != null)
                {
                    _consumerPool.Stop();
                    _consumerPool.Dispose();
                    _consumerPool = null;
                }

                if (_serviceContainer != null)
                {
                    _serviceContainer.Stop();
                    _serviceContainer.Dispose();
                    _serviceContainer = null;
                }

                if (ControlBus != this)
                {
                    ControlBus.Dispose();
                }

                _unsubscribeEventDispatchers();

                InboundPipeline.Dispose();
                InboundPipeline = null;

                OutboundPipeline.Dispose();
                OutboundPipeline = null;

                if (_eventAggregatorScope != null)
                {
                    _eventAggregatorScope.Dispose();
                    _eventAggregatorScope = null;
                }

                _eventAggregator = null;

                Endpoint = null;

                if (_counters != null)
                {
                    _counters.Dispose();
                    _counters = null;
                }

                if (PoisonEndpoint != null)
                {
                    PoisonEndpoint = null;
                }
            }
            _disposed = true;
        }
Exemple #4
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }
            if (disposing)
            {
                if (_consumerPool != null)
                {
                    _consumerPool.Stop();
                    _consumerPool.Dispose();
                    _consumerPool = null;
                }

                if (_serviceContainer != null)
                {
                    _serviceContainer.Stop();
                    _serviceContainer.Dispose();
                    _serviceContainer = null;
                }

                if (ControlBus != this)
                {
                    ControlBus.Dispose();
                }

                if (_performanceCounterConnection != null)
                {
                    _performanceCounterConnection.Dispose();
                    _performanceCounterConnection = null;
                }

                _eventChannel = null;

                Endpoint = null;

                if (_counters != null)
                {
                    _counters.Dispose();
                    _counters = null;
                }

                EndpointCache.Dispose();
            }
            _disposed = true;
        }
        //Just here to support Subscribe(Type)

        public void Start()
        {
            if (_started)
            {
                return;
            }

            _consumerPool = new ThreadPoolConsumerPool(this, ObjectBuilder, _eventAggregator, _receiveTimeout)
            {
                MaximumConsumerCount = MaximumConsumerThreads,
            };
            _consumerPool.Start();

            _serviceContainer.Start();

            _started = true;
        }