0

I have case in that we need to have multiple producer and multiple consumer. Producers & consumers should run on separate Task.

When I googled it I saw multiple options available in C# like BlockingCollection, DataFlow, Queue etc.

I have tried all of them in my POC, what I see is those are not fitting in my projects requirement.

My requirement is that Producers may spin Tasks asynchronously but there Consumers must do there processing job serially e.g. below

Producer1 - This should polls message for processing and pass it to below consumers

 Consumer1
 Consumer2
 Consumer3

but processing should happen serially i.e. Consumer1 should process all message first then consumer2 and consumer3

Producer2

 Consumer1
 Consumer2
 Consumer3

same should happen with producer2 also.

I have tried below links for my reference. https://www.codeproject.com/Articles/1112510/TPL-Producer-Consumer-Pattern-Thread-Safe-Queue-Co

https://jeremydmiller.com/2016/08/09/building-a-producer-consumer-queue-with-tpl-dataflow/

http://www.dotnetcurry.com/patterns-practices/1407/producer-consumer-pattern-dotnet-csharp

CSharpDev
  • 370
  • 1
  • 7
  • 28
  • So you're saying all consumers get all messages? That's not the typical producer/consumer problem and sounds more akin to some form of pipeline. – Damien_The_Unbeliever Mar 14 '18 at 14:47
  • Did you try a blocking collection before Consumer1 and then another one between each Consumer after that? i.e. a pipeline? – Ian Mercer Mar 14 '18 at 15:13
  • @Damien_The_Unbeliever, Nope you got it correct, producer has messages for all 3 consumer but they will be in order hence I need them to finish in order only. – CSharpDev Mar 15 '18 at 08:04

0 Answers0