Does projections support persist state object?

Hello,

I have a projection that emit new event based on the value of certain attribute of aggregate entity (user), for example, country field of an user, but not all events for that user will contain the info for country. So I store the country information in the state object, when i want to retrieve the country info, i just read it from the state object. Problems for me now are:

  1. when eventstore application stopped, the state object in the projection would also be lost, so if i restart the projection after event store back up, i can’t reuse the data i stored in the state object previously

  2. is this the correct way to use projection? (thought of building read model in my own application, but that introduce extra work effort)

Regards,

Run Yang

Also, is it possible to read stream inside a projection? a valid user case is that my projection logic would depends on data from other stream, like i have a stream for a user, and there is also a stream for countries, i would like to refer to the country stream when processing user event.

  1. when eventstore application stopped, the state object in the projection would also be lost, so if i restart the projection after event store back up, i can’t reuse the data i stored in the state object previously

Event store handles your state through master takeovers/restarts etc. Are you not seeing this? The signature of a function in projections is:

f(state,event) => state

The returned state is automatically memoized by projections.

Cheers,

Greg

Thank you very much for the response, Greg.

Let me put it this way, if i stop my projection, later i want to start the projection, i would like to load my state object from somewhere (say a files), is there existing function support that? Or how can i add extra functions(ajax call, external library, etc) into projection?

Regards,

Run Yang

We automatically load your state (anything in the state parameter) no need for you to do it

hi Greg,

You are right, this time it worked, i must have being doing something wrong, thanks!

Hi Run,

do you have a solution for extra libraries used during run of a projection?

I making ajax requests might be too expensive to in projections, but e.g. formating date is ok…

regards, stej