Questions on replay and event store appending?
The complexity to deal with event store and datastore seems too high and lot of more work for simple challenge, which I think Axon is excellently positioned for.
The business need for a domain aggregate is something much more simpler
- query event log of an aggregate root for a range of events (without snapshot events)
something like
DomainEventStream queryEventLog(…) on aggregate root for classes which extend AbstractAnnotatedAggregateRoot or Entity Aggregates
if the query Method with criteria cannot be granular enough to filter the events based on events field information allow for further creation of filtered stream in memory i.e.
DomainEventStream temporaryStream.remove(DomainEvent unwantedCouldNotQueryEvent)
- replay on a new in-memory new temporary aggregate (no eventstore or db needed or datasource needed with transactions and commits) to build a what if state.
somethink like …
AggregateRoot temporaryAR = new AggregateRoot(String temporaryId);
temporaryAR.replay(DomainEventStream temporaryStream);
and temporaryAR.getXXXX() for reading resulting state from the AR to compute resluting state and then use that information for error correction or what if business logic, however discard the temporary AR from memory instantly after calculations.
Would this be possible with the design enhancements you are envisioning. It would fulfull a lot of needs of the Accounting patterns discussed by fowler above vs building a full fledged parallel system with datasource transactions, persistence etc, which may also be good additional features for usage.
If this cannot be done by Axon, the other alternative is to keep a collection of eventLog within aggregate as a field append the events on the event handlers and build custom query methods for business domain, create a new pojo Aggregate root in memory e.g.
public class MyAR extends AbstractAnnotatedAggregateRoot{
private CustomCollection eventLog;
private StateField stateField1;
private StateField stateField2;
public MyAR(Stting Id){
}
public doWhatIfOrInHindsightMethod(…){
Collection stream = eventLog.queryByCustomCriteria()
MyAr tempAr = new MyAr(tempUUID);
for (each itemEvent in stream)
{
tempAr.handle(itemEvent);
}
tempAr.getResultantState();
//do more logic and apply any other events as necessary for regular processing and applycation of correction state deduced from the in-memory parallel model.
}
@EventHandler
public handle(Event1 event){
//update state
eventLog.add(event, whenhappened, whenNoticed);
}
@EventHandler
public handle(Event2 event){
//update state
eventLog.add(event, whenhappened, whenNoticed);
}
}
but that would defeat the purpose of the event sourced log and create duplication of event information in log and on the aggregate.
Please give this your thoughts and input/Consideration for future.
Cheers…