DataBlock Lifetime and completion
-
Monday, December 31, 2012 1:37 PM
I'm working on a lightweight message bus using TDF. You can see the current implementation at https://gist.github.com/4416655.
Currently I'm using a single BroadcastBlock<T> to broadcast all messages.
- Is this likely to scale well with large numbers of messages?
- Would I be better off maintaining a BroadcastBlock<T> instance per message type?
Another problem I am facing is how we can inform the caller when a message has been handled by all consumers.
If I call BroadcastBlock<T>.Complete().Completion.Wait() I can do this but it means I can no longer use the BroadcastBlock for broadcasting messages.
It's not possible for me to create a new BroadcastBlock per message instance as I need to support subscribing/unsubscribing.
It seems that the SendAsync Task returns when the message has been sent to all consumers, not when the consumer has finished processing.
Thanks
- Edited by Ben Foster Monday, December 31, 2012 1:42 PM
- Edited by Ben Foster Monday, December 31, 2012 1:44 PM
All Replies
-
Tuesday, January 08, 2013 6:52 PMOwner
Hi Ben-
If you want to track when each individual message has been handled by all consumers, you'll need to implement that support manually, since what it means to be "handled" is really up to your implementation. Rather than sending your data T along by itself, you'd likely want to send a Wrapped<T>, where Wrapped<> is your own custom message wrapper data structure with additional information about message being propagated. That additional information could include a counter that each consumer would decrement to denote that they were done processing it, as well as some sort of synchronization primitive (potentially a TaskCompletionSource) that would be signaled when the count reaches 0.
- Proposed As Answer by Stephen Toub - MSFTMicrosoft Employee, Owner Tuesday, January 08, 2013 6:52 PM
- Marked As Answer by Stephen Toub - MSFTMicrosoft Employee, Owner Thursday, January 17, 2013 1:04 AM

