0

I'm implementing a CQRS/ES solution with Akka.Net and Akka.Net.Persistence with a SQL Server Journal. So far everything seems to work great with the default sql-server plugin.

Last thing to verify was the ability to be able to reload/replay events from a specific AR, e.g. to rebuild a read model or to fill a newly implemented projection for a read model. The way I would go about this is reading the events from de DB and putting them on the eventbus or directly into the mailbox of the "projection actor".

I can't seem to find any examples of manually reloading events and besides querying the Journal table myself (executing sql query) and using the built-in serializer I'm basically stuck with this.

Is there anyone trying to do, more or less, the same thing?

schepersk
  • 31
  • 5

1 Answers1

3

Depending on your needs there are few ways:

  1. Using PersistentView - it's a dedicated actor, which is correlated with some specific persistent actor, and it's able to receive it's events to build some different state from them. It's readonly. Pros: it's keeping itself up to date with events produced by peristent actor (however some delay between updates applies). Cons: it's related with a single actor, it cannot be used to aggregate event's from many of them.
  2. Using journal query (SQL journals only) - it allows you to query journal using some specific filters. Pros: it can be used across multiple aggregates. Cons: it's not automatically kept up to date, you need to send subsequent queries to get updates. I'm not sure, if it has official documentation, but flow itself is described here.

PS: some of the journal implementations have their own dedicated serializers, but not SQL-based ones. And belive me, you never want to rely on default serializer for persisting events.

Bartosz Sypytkowski
  • 7,463
  • 19
  • 36
  • Thanks for your response! PersistentView is definetly not what I'm looking for. The way I'm setting up the read model projections now is publishing the events on the EventStream. The projection actor router is subscribing to events on the EventStream. This setup seems to work just fine. The issue I'm trying to explain is when there is a need for a new read model (and projection) of when a read model needs to be rebuilt. In our own, custom, event store, we just load the needed events from the event store and put them on a queue for reprocessing.. – schepersk Feb 17 '16 at 08:31
  • Also, why should one not use the default serializer from Akka.Persistence.Common.Sql? Granted, using our own serializer for persisting events would be more convenient in my scenario.. – schepersk Feb 17 '16 at 08:51
  • Storing objects have different characteristics than sending them over the wire as fast as possible. But major reason is that default serializer may (and most probably will) be changed in future versions of Akka.NET. – Bartosz Sypytkowski Feb 17 '16 at 10:28
  • What is the easiest way of plugging in your own event serializer in the sql server persistence? – schepersk Feb 17 '16 at 10:57
  • SQL-based plugins use the default serialization mechanism. You can read more about it in the [documentation](http://getakka.net/docs/Serialization). – Bartosz Sypytkowski Feb 17 '16 at 13:11