public async Task StartAsync( IConsumer <byte[], byte[]> consumer, IEnumerable <TopicPartition> partitions, CancellationToken stopCancellationToken = default) { this.offsetManager = new OffsetManager( new OffsetCommitter( consumer, this.configuration.AutoCommitInterval, this.logHandler), partitions); await Task.WhenAll( Enumerable .Range(0, this.configuration.WorkerCount) .Select( workerId => { var worker = new ConsumerWorker( consumer, workerId, this.configuration, this.offsetManager, this.logHandler, this.middlewareExecutor); this.workers.Add(worker); return(worker.StartAsync(stopCancellationToken)); })) .ConfigureAwait(false); this.distributionStrategy = this.distributionStrategyFactory(this.dependencyResolver); this.distributionStrategy.Init(this.workers.AsReadOnly()); }
public async Task StopAsync() { var currentWorkers = this.workers; this.workers = new List <IConsumerWorker>(); await Task.WhenAll(currentWorkers.Select(x => x.StopAsync())).ConfigureAwait(false); this.offsetManager?.Dispose(); this.offsetManager = null; }