I am trying to come up with a solution that involves Kafka with .Net
This video gives a nice introduction and also suggests configuring for Throughput or Latency.
The related code here has configuration values like so:
config.Add("batch.num.messages", "50000")
config.Add("queue.buffering.max.ms", "300")
There's also the mention of using
Collections.Concurrent.BlockingCollection
in the video.
What I currently have is this:
- A Web API call writes data into a table (MS-SQL) which has a column named
PublishedStatus
whose value is set to 1(ReadyForPublishing)
. The data is also added to a List. - Apart from doing the above the API uses two classes one deriving from
BackgroundService
and the other fromIHostedService
2.1 The one using BackgroundService
takes the list from Step 1 and tries to Publish
them to Kafka
2.2 The one using IHostedService
is for resiliency and will query the table from Step 1 for all the records in certain time range which could not be published due to some failure and tries to publish them again.
- Records are marked as
Published
orErrorPublishing
based on the response of theProduceAsync
call.
After watching the video I was looking for examples that could show the usage of BlockingCollection
because the target is Throughput here.
Question 1: Can someone please point to a resource that I can get started with using BlockingCollection
? If BlockingCollection
is not recommended what are my other options?
When we use the batch option, what is queue or collection that this library uses in which I can add the data instead of to a list in Step1 above?
Question 2: Can a framework like Polly be helpful here when designing for resiliency?
I have an option here to redesign/refactor the existing implementation as described above, hence these queries.
Appreciate any help/guidance.