@afmorris you could try a static factory with the iactorref's .. is a bit nicer than actor selection which is recomened for remote system in practice.. Partial constructer DI would be nice ..my 2 cents
hi guys, got a q about Akka.Persistence and read model(projection) building. I used NEventStore before. There was a global sequence number. So when I need to create some projection I was subscribing to all events basically with single sequence id to track the state of my projection. As far as I understood there is no such concept in Akka.Persistence and maybe for the best-streams are independent and those are our portioning point. Having all of this, I was wondering how to projection building done? I can try to imagine it this way: On start of the Projection Service, I read(subscribe) all the stream ids(is there such API?) and for every single one I create a subscription per stream. So as a result I have as many individual projections as we have streams. Question: is this how it should be done? Something to worry about?
And the way you should design your system to prevent problems in highly statefull clusters, is always tricky. And can differ wildly depending on what kind of work your doing, or how your network topology is structured.
In akka persistence there's no global sequence number - each stream (identified by persistenceId) has its local sequence nr. This is mostly because global sequence number is not viable option in distributed systems without crippling performance. For the same reason, currently there's no API inside read journal to get live stream of all incoming events: however there's such proposal for databases, that don't support sharding.
Also you shouldn't write to a single event stream concurrently from multiple actors. This will corrupt event stream. In akka this isn't usually a problem, as you may define a simple actor working as aggregate and provide all event stream data through it - if you need simple distribution in case when you have a lot of such actors, you could i.e. use cluster sharding.
@Horusiath thanks a lot. Re: projections. So the right approach is to listen for the stream of the stream ids and for each stream id I should create actor, which subscribes for the corresponding stream? What if there are too many?
@maxcherednik right now this is very limited and inefficient approach. If you need to just get a subset of all events across different streams, you could wrap your events using Tagged event with tags attached to it. The you can make projections based on specific tag
Hm... I thought that would be more or less ok. Cause I don't see the other way of doing the projection here. I can't think of a specific tag. All I know, I have streams and I need to have the latest state in memory.
In fact, I am just guided by the API of the specific eventstore. For instance, NeventStore and geteventstore they don't have an API, which returns list of streams, but they have a global sequence.
After all I need to have all the streams in memory(there is a cleaning logic of course), so that I could do some real time calculations. And for me is not really important if it's a global state or set of stream states. Second one seams easier, since streams are "living" independently
So far I am using Neventstore and global sequence. Which I don't really like. Looking into akka. So considering options.
Basically you can think of this as an in-memory read-side. Why in memory? Cause I need to react on every new event on every stream. One of the streams changed? I need to recalculate it's value, so the value of the sum of those projections.