5
votes

Background

I'm using the EventStore (from geteventstore.com) in a project. So fare I have implemented the write side of the application. That is I can read and write events for a given aggregate.

Now i'm on the read side and need to subscribe to a stream. I'm using the java api and everything is also working here.

Now the problem

The stream doesn't exist... I have to create a projection that aggregates events from different streams to a single stream for my read model.

How can I create a projection via the api? Preferably with the java api, but the http api would also do.

Elaporates

As projections are the means for a readmodel to get the exact events it needs, new projections will be created as the business needs changes. My idea is therefore that a readmodel service will check for and potentially create the projection it needs when it starts up.

It will be unacceptable to manually create the projections before starting the service. That would be like manually migrating your sql db.

1
Want to automate the projection code creation and maintenence using Java Code only - is there a possible solution ? - Abdeali Chandanwala
i'd be interested in an answer to this for using the HTTP API. the eventstore.org/docs/http-api/swagger/… aren't clear on where/how to include the projection's javascript. - hwjp

1 Answers

0
votes

From http://docs.geteventstore.com/dotnet-api/4.0.0/projections/

public Task CreateContinuousAsync(string name, string query, UserCredentials userCredentials = null)

Creates a projection that will run until the end of the log and then continue running. The query parameter contains the javascript you want to be created as a one time projection. Continuous projections have explicit names and can be enabled/disabled via this name

There are other options like creating a one-time projection, etc.

It refers to the .NET API. Since there seems to be no specific documentation for the Java API I am assuming they are similar.