Task Remove(BatchConsumer <TMessage> consumer)
        {
            if (_currentConsumer == consumer)
            {
                _currentConsumer = null;
            }

            return(TaskUtil.Completed);
        }
Beispiel #2
0
        async Task IConsumerFactory <IConsumer <TMessage> > .Send <T>(ConsumeContext <T> context, IPipe <ConsumerConsumeContext <IConsumer <TMessage>, T> > next)
        {
            var messageContext = context as ConsumeContext <TMessage>;

            if (messageContext == null)
            {
                throw new MessageException(typeof(T), $"Expected batch message type: {TypeMetadataCache<TMessage>.ShortName}");
            }

            BatchConsumer <TConsumer, TMessage> consumer = await _collector.Run(() => Add(messageContext), context.CancellationToken).ConfigureAwait(false);

            await next.Send(new ConsumerConsumeContextScope <BatchConsumer <TConsumer, TMessage>, T>(context, consumer)).ConfigureAwait(false);
        }
Beispiel #3
0
        async Task <BatchConsumer <TConsumer, TMessage> > Add(ConsumeContext <TMessage> context)
        {
            if (_currentConsumer != null)
            {
                if (context.GetRetryAttempt() > 0)
                {
                    await _currentConsumer.ForceComplete().ConfigureAwait(false);
                }
            }

            if (_currentConsumer == null || _currentConsumer.IsCompleted)
            {
                _currentConsumer = new BatchConsumer <TConsumer, TMessage>(_messageLimit, _timeLimit, _collector, _dispatcher, _consumerFactory, _consumerPipe);
            }

            await _currentConsumer.Add(context).ConfigureAwait(false);

            return(_currentConsumer);
        }
        BatchConsumer <TConsumer, TMessage> Add(ConsumeContext <TMessage> context)
        {
            if (_currentConsumer != null)
            {
                if (context.GetRetryAttempt() > 0)
                {
                    _currentConsumer.ForceComplete();
                }
            }

            if (_currentConsumer == null || _currentConsumer.IsCompleted)
            {
                _currentConsumer = new BatchConsumer <TConsumer, TMessage>(_messageLimit, _timeLimit, _scheduler, _consumerFactory, _consumerPipe);
            }

            _currentConsumer.Add(context);

            BatchConsumer <TConsumer, TMessage> consumer = _currentConsumer;

            return(consumer);
        }
        public virtual async Task Send <T>(ConsumeContext <T> context, IPipe <ConsumerConsumeContext <BatchConsumer <TMessage>, T> > next)
            where T : class
        {
            var messageContext = context as ConsumeContext <TMessage>;

            if (messageContext == null)
            {
                throw new MessageException(typeof(T), $"Expected batch message type: {TypeMetadataCache<TMessage>.ShortName}");
            }

            BatchConsumer <TMessage> consumer = await _collector.Collect(messageContext).ConfigureAwait(false);

            try
            {
                await next.Send(new ConsumerConsumeContextProxy <BatchConsumer <TMessage>, T>(context, consumer)).ConfigureAwait(false);
            }
            finally
            {
                if (consumer.IsCompleted)
                {
                    await _collector.Complete(messageContext, consumer).ConfigureAwait(false);
                }
            }
        }
 public Task Complete(ConsumeContext <TMessage> context, BatchConsumer <TMessage> consumer)
 {
     return(_collector.Run(() => Remove(consumer)));
 }