8 februarie 2012 03:07
When multiple recievers are registered to recieve the same message type on the same CCR port only one of the reciever delegates will be triggered per-message post and to my understanding exactly which delegate gets fired is not always deterministic. This makes sense for the general case and is how CCR is typically used.
That said, how cool would it be if I could activate a single CCR port such that whenever I post a message to it, an arbitrary number of recievers could get that message too. It would be like an event where each of the event handlers is a task and gets scheduled to run asynchronously. I can think of about 2-dozen places I could use such a thing in my existing code right now.
So, I have two lines of questions.
1.) Has someone already done this? If so, are you willing to share your code or advice with me? If not, why not, am I missing something here?
2.) If nobody has already had this idea and implemented a solution, does anyone have ideas for how I could go about creating such a thing? I could be wrong, but it doesn't seem like it is as simple as creating a custom composite port, is it?
17 februarie 2012 19:15Moderator
Which receiver handles an available message is deterministic, in the sense that it is always the earliest registered receiver that can handle the message.
This question occasionally comes up, both internally and externally, but this pattern is not addressed by CCR (it is addressed by the DSS programming model). I personally wouldn't use a custom port to do this, I think there is a risk of overloading the understood semantics for some syntactic convenience. Instead if you want to do this with CCR primitives, you might model a small CCR service, derived from CcrServiceBase and use an interleave to protect the state (the list of subscribers). Support a portset of <Subscribe,Unsubscribe,Publish> and deal with these messages via an interleave.
- Propus ca răspuns de gunnnMicrosoft Employee, Moderator 17 februarie 2012 19:15
4 martie 2012 23:25
gunnn, your response was excellent.
I've taken your advice and ran with it. I've written my own CCR PubSub service and posted all its source code, along with a full discussion of the design and implementation to this blog post:
Thanks for the advice. I'm pretty happy with how simple this ended-up being.
- Marcat ca răspuns de Kobe1815 4 martie 2012 23:25