I'm implementing producer-consumer in asp.net core app using hosted service. I was able to get it working to a point where consumer is processing items from _recordProcessingChannel.ReadAllAsync() synchronously.
I'm trying to split result of _recordProcessingChannel.ReadAllAsync() into several parallel tasks.
For ex.: I have 10000 items read from channel and i want to split this work into 4 seperate tasks and process 2500 items per ICMService.
consumer:
await foreach (var record in _recordProcessingChannel.ReadAllAsync())
{
using var scope = _serviceProvider.CreateScope();
var processor = scope.ServiceProvider.GetRequiredService<ICMService>();
processor.UploadRecord(record);
}
reader:
public IAsyncEnumerable<RecordData> ReadAllAsync(CancellationToken ct = default) => _channel.Reader.ReadAllAsync(ct);
Thank you in advance for any help provided