orleans icon indicating copy to clipboard operation
orleans copied to clipboard

Can we have ObserverManager implemented in Orleans

Open j0nimost opened this issue 3 years ago • 5 comments

While following the Docs on how to implement Observers; I noticed that ObserverManager is not defined in the Orleans package but instead its defined here: ObserverManager

j0nimost avatar Jul 14 '22 08:07 j0nimost

TLDR; there's an open item to resurrect that long lost friend for v4.x so there's a possibility you may have your wish granted.

Long story, the ObserverSubscriptionManager was moved to a legacy package back in v2.x, you can see the code here: https://github.com/dotnet/orleans/blob/v2.4.5/src/Orleans.Core.Legacy/Async/ObserverSubscriptionManager.cs

It doesn't look like that code survived the cut to v3.x, let alone to v4.x, and that's probably for the best. That implementation will root subscriptions that die off without unsubscribing, so you end up with memory leaks over time if there's nothing to notify. There's a best effort to remove them on failure to reach them but that only works if there's something to send to them. And then if those subs are just experiencing a wobbly and are not dead, the "connection" breaks without recovery. It's not a reliable cycle. So until the team or a contributor writes a more robust implementation, it's best to write your own custom manager, with active cleanup logic specific to your use case. Or better yet, just use streams, the memory provider works like a charm for these things if you don't care about persisting messages.

JorgeCandeias avatar Jul 14 '22 09:07 JorgeCandeias

I really wanted to implement a subscription model since my instance I would like to trigger it. It's so unfortunate that they left it since in this particular case I want to use it within Orleans and not download some CQRS package. The documentation is SO BAD and scanty that you have to literary stumble upon a feature. I have no clue where I start in writing an implementation of an ObserverManager. So, i use the demo one

j0nimost avatar Jul 14 '22 12:07 j0nimost

I recommend you just use the built-in Memory Streams provider with the streaming model and forget the observer manager ever existed. Memory Streams work like a charm for non-persisted messaging, no CQRS modelling involved, just pub and sub and Orleans will clean up dead subs for you. It's built into the Orleans base packages, no extras needed.

Note that the Orleans development team is tiny and they have only very recently joined the dotnet umbrella in an official capacity. And with any bleeding edge tech in constant research, the docs will lag by years. I think this will improve a lot as integration with the greater dotnet process control practices increases and they get the benefit of dedicated technical writers.

JorgeCandeias avatar Jul 14 '22 13:07 JorgeCandeias

We should also bring ObserverManager back. There is a version from the tests which you ought to be able to copy into your project: https://github.com/dotnet/orleans/blob/main/test/Grains/TestGrains/ObserverManager.cs

ReubenBond avatar Jul 14 '22 18:07 ReubenBond

A PR for this would be welcome, by the way, to move ObserverManager into Orleans.Core

ReubenBond avatar Jul 14 '22 18:07 ReubenBond