event-sourcingprooph

Get current no from prooph event store


I try to update a projection from event store. The following line will load all events:

$events = $this->eventStore->load(new StreamName('mystream'));

Currently i try to load only not handled events by passing the fromNumber parameter:

$events = $this->eventStore->load(new StreamName('mystream'), 10);

This will load all events eg from 15 to 40. But i found no way to figure out which is the current/highest "no" of the results. But this is necessary for me to load only from this entry on the next time.

If the database is truncated (with restarted sequences) this is not a real problem cause i know that the events will start with 1. But if the primary key starts with a number higher than 1 can not figure out which event has which number in the event store


Solution

  • When you are using pdo-event-store, you have a key _position in the event metadata after loading, so your read model can track which position was the last you were working on. Other then that, if you are working with proophs event-store projections, you don't need to take care of that at all. The projector will track the current event position for all needed streams internally, you just need to provide callbacks for each event where you need to do something.