1

I have a class named Foo producing Bar (immutable data) very fast (many times a second).
I have many consumers looking to consume the data produced. Here is my requirements :

  1. It has to be asynchronously so the producer is never blocked or waiting
  2. All consumers must receive the same data
  3. If for some reason one consumer is delay, it should consume the latest message
  4. Every minute there is a message that must be sent and received by all consumers.
  5. I really want to abstract my consumers from any data flow implementation (Like TPL for example), simply to subscribe to the producer.

My logical is telling me to use events, but event may impact my performance,
I once used the TPL library but only for ActionBlock, so I'm lacking in my knowledge in this area.

What solution fits my case ?

Br4infreze
  • 342
  • 3
  • 11
  • 1
    Take a look at the Dataflow library - https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/dataflow-task-parallel-library – Camilo Terevinto Aug 03 '21 at 14:53
  • 1
    In particular, it sounds like the BroadcastBlock would be a good fit for your requirements https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.dataflow.broadcastblock-1?view=net-5.0 – TJ Rockefeller Aug 03 '21 at 14:58
  • 1
    Look at [channels](https://devblogs.microsoft.com/dotnet/an-introduction-to-system-threading-channels/) – Alexander Petrov Aug 03 '21 at 15:28
  • *"If for some reason one consumer is delay, it should consume the latest message"*: Do you mean that consumers are never allowed to skip messages, and that the delivery of all messages to all consumers should be guaranteed? In this case this question comes to mind: [BroadcastBlock with guaranteed delivery in TPL Dataflow](https://stackoverflow.com/questions/22127660/broadcastblock-with-guaranteed-delivery-in-tpl-dataflow). You may also find this question inspiring: [Factory for IAsyncEnumerable or IAsyncEnumerator](https://stackoverflow.com/questions/61540896). – Theodor Zoulias Aug 04 '21 at 02:47

0 Answers0