See reply inline.
you could use another table for the locally applied events, so that you
can easily remove them. You may also need to rebuild the query models
Sounds like a good idea. Do you have any hint how I could achive that the
events are stored in different tables depending on their source? Probably
I'd have to modify EventSourcingRepository in some way.
If you use the JpaEventStore, you can extend the DefaultEventEntry store
and implement your own methods for createDomainEventEntry,
snapshotEventEntryEntityName. The first two methods will need to return a
subclass of DomainEventEntry/SnapshotEventEntry with the proper JPA @Entity
However, if you only store the aggregate snapshot when synchronizing, you
don't need to do anything with separate tables. All you would then need to
do is clear the DomainEventEntry tables and download new snapshots. Then,
your event store is up to date again.
I would sync the query model in the same way. Simply download new/modified
query table entries from the server on sync.
Just wondering, are you copying the whole application state locally, or
are you selecting specific aggregates (and related read models) to
synchronize? If you do so, theoretically, you only need to sync the read
models and snapshots of the current aggregate state locally. You may not
need any history of your aggregates.
My requirement just says that the current state of some aggregates has to
be on the client and that all changes from the client needs to be
synchronized to the server. To keep it simply, I'm going to copy the whole
event stream from server to client with the opportunity to optimize it
later in the way you described.
As described above, you could store snapshots only. In that case, you
would query for each aggregate identifier and its maximum sequence number.
If that sequence number is higher than the information you have stored
locally, you use the snapshotter to create a snapshot, and store that in
the local Snapshot table. In future versions, you could limit this to the
aggregates that the client "subscribed" to.
Actually on the client the same (web-) application will run as on the
server. There is a configuration setting telling it that it runs on the
client which changes some things:
- only commands for certain aggregates are accepted (using an
interceptor). The GUI will reflect this restrictions
- all accepted commands will be serialized to en extra database table
- synchronisation will be enabled
At the moment I try to send the server's events to the client and have the
following problem. I visit all events on the server and send them as
Event-Stream to the client. There I'd like to add it to the event store. My
problem is that saving events to the event store requires a "type"
parameter which is not available in the EventVisitor. Do you have an idea
how to solve this?
Otherwise I would force the client and the server to use JpaEventStore and
directly access/copy the stored entities.
Valid point. The API currently doesn't allow you to get the type
parameter. The only way is to access the store directly, unfortunately. I
think I will need to add the type as a parameter to the visitor in future