Exemplo n.º 1
0
 private void RemoveHandledMessage(ConsumeResult <Ignore, string> message)
 {
     if (_consumingQueues.TryGetValue(message.ToKeyString(), out var processQueue))
     {
         processQueue.RemoveMessage(message);
     }
 }
Exemplo n.º 2
0
        public void EnterConsumingQueue(ConsumeResult <Ignore, string> message)
        {
            TopicPartitionProcessQueue <Ignore, string> processQueue;

            if (_consumingQueues.TryGetValue(message.ToKeyString(), out processQueue))
            {
                processQueue.AddMessage(message);
            }
            else
            {
                processQueue = new TopicPartitionProcessQueue <Ignore, string>(message.Topic, message.Partition);
                processQueue.AddMessage(message);
                _consumingQueues.TryAdd(message.ToKeyString(), processQueue);
            }

            if (_isSequentialConsume)
            {
                _consumeWaitingQueue.Add(message);
            }
            else
            {
                Task.Factory.StartNew(async m =>
                {
                    await HandleMessageAsync(m);
                }, message);
            }

            var unconsumedMessageCount = processQueue.GetMessageCount();

            if (unconsumedMessageCount > _consumer.Setting.ConsumeFlowControlThreshold)
            {
                var delayMilliseconds = FlowControlUtil.CalculateFlowControlTimeMilliseconds
                                        (
                    unconsumedMessageCount,
                    _consumer.Setting.ConsumeFlowControlThreshold,
                    _consumer.Setting.ConsumeFlowControlStepPercent,
                    _consumer.Setting.ConsumeFlowControlStepWaitMilliseconds
                                        );

                _logger.InfoFormat($"{message.ToKeyString()} unconsumed message[{unconsumedMessageCount}], consume too slow, need to wait {delayMilliseconds}ms.");
                Thread.Sleep(delayMilliseconds);
            }
        }
Exemplo n.º 3
0
        public void EnterConsumingQueue(ConsumeResult <Ignore, string> message)
        {
            if (_consumingQueues.TryGetValue(message.ToKeyString(), out var processQueue))
            {
                processQueue.AddMessage(message);
            }
            else
            {
                var queue = new TopicPartitionProcessQueue <Ignore, string>(message.Topic, message.Partition);
                queue.AddMessage(message);
                _consumingQueues.TryAdd(message.ToKeyString(), queue);
            }

            if (_isSequentialConsume)
            {
                _consumeWaitingQueue.Add(message);
            }
            else
            {
                Task.Factory.StartNew(HandleMessage, message);
            }
        }