I’m trying to do the same thing using Axon Framework 4.8.0, but without success. I also can’t find documentation or examples on how to achieve this. So I’m wondering if anyone was able to do this?
I’ve debugged the internal code of Axon, and it seems that the expectedVersion
argument in Repository.load(String aggregateIdentifier, Long expectedVersion)
is never actually being used to limit the stream of domain events.
The way I’ve tested it (and didn’t work) was:
var message = new GenericMessage(...);
var unitOfWork = DefaultUnitOfWork.startAndGet(message);
var personAggregate = personEventSourcingRepository.load(id, sequence);
personAggregate.execute(p -> {
log.info("At this point I incorrectly get the latest version");
});
// Statement below also returns the latest version incorrectly
var person = personAggregate.getWrappedAggregate().getAggregateRoot();
Edit:
It seems this question was asked a long time ago, with a proposal implementation to add support to the framework. But there was no further reply