3

According to CQRS à la Greg Young, event handlers (and the downstream event denormalizers) react on incoming events that were published before by the event publisher.

Now lets suppose that at runtime we want to add a new event denormalizer: Basically, this is easy, but it needs to get to its data to the current state.

What is the best way to do this?

Should I send an out-of-order request to the event store and ask for all previously emitted events?

Or is there a better way to do this?

Golo Roden
  • 140,679
  • 96
  • 298
  • 425

3 Answers3

4

You can fetch and replay all (required) events against the new handler. This can be done in a separate process since what you essentially want is to get the persisted view models into the proper state.

Have a look at Rinat Abdullin's Lokad.CQRS sample project for a production example. Especially the SaaS.Engine.StartupProjectionRebuilder might be an interesting source even though it's rather complex.

Dennis Traub
  • 50,557
  • 7
  • 93
  • 108
  • Thanks for your answer and the link. I think that it's a good idea to run this as a separate process, it's also basically clear to me how to do it. The only question is: Who kicks this off? The event handler? The administrator "manually"? ...? – Golo Roden Nov 18 '12 at 17:33
  • I've seen that basically http://stackoverflow.com/questions/2559096/cqrs-how-to-handle-new-report-tables-or-how-to-import-all-history-from-the-e?rq=1 answers this question. – Golo Roden Nov 18 '12 at 17:40
4

One can also build the projections so that they remember what event they saw last. Then on any startup, they ask for this event and all forward. Re-starting an old projection and building a new one then become roughly the same thing.

Sebastian Good
  • 6,310
  • 2
  • 33
  • 57
2

If you embrace bounded context complex integration you may need to drop the entire read model and rebuild it.

Narvalex
  • 1,824
  • 2
  • 18
  • 27