Hello, we have been using the Axon Framework in our product for several years now. In order to implement a new feature, we have decided to utilize the aggregate polymorphism design concept, as we wish to reuse certain parts of the business logic across two aggregates of a similar type. Generally speaking, it has been functioning well. However, we have encountered two issues when introducing snapshotting.
To replicate these issues, we cloned the following GitHub project: GitHub - idugalic/axon-polymorphism-demo: Axon and OOP (Inheritance, Polymorphism).
We added a file named AxonConfiguration.java and configured a default snapshot trigger, setting the threshold to 1 for testing purposes.
@Configuration
public class AxonConfiguration {
@Bean
public SnapshotTriggerDefinition defaultSnapshotTrigger(Snapshotter snapshotter) {
return new EventCountSnapshotTriggerDefinition(snapshotter, 1);
}
}
Subsequently, we included the snapshotTriggerDefinition as a parameter in the @Aggregate annotation of the abstract class Bird. Although we couldnât find any relevant information in the documentation, we believed this to be the best location for it.
@Aggregate(snapshotTriggerDefinition = "defaultSnapshotTrigger")
@NoArgsConstructor(access = AccessLevel.PACKAGE)
abstract class Bird {
...
We ran AxonServer in a Docker container and implemented a simple REST controller to send commands. After launching the application, we successfully sent the HatchEagleCommand command but still received an error message in the logs:
o.a.eventsourcing.AbstractSnapshotter: An attempt to create and store a snapshot resulted in an exception. Exception summary: Aggregate Type is unknown in this snapshotter: pro.idugalic.axonpolymorphism.command.Bird
While debugging the code, we discovered that the aggregateFactory in the getAggregateFactory method (in org.axonframework.spring.eventsourcing.SpringAggregateSnapshotter) was null. This led to the aforementioned error being logged by org.axonframework.eventsourcing.AggregateSnapshotter. We are concerned that this error may result in undefined behavior. We are currently using axon-spring-boot-starter version 4.7.3.
The second issue we encountered relates to the aggregateType of a snapshot. After sending the FlyCommand twice, we noticed that AxonServer had created a snapshot, with the aggregateType listed as âEagleâ. However, when we renamed the Eagle aggregate to âXEagleâ and sent the hatching and flying commands again, the aggregateType in the new snapshot was âPenguinâ, which was unexpected. Upon debugging into the repository, we found that the subtypes of the aggregateFactory were correct, but the aggregateType seemed to be the first one listed in the subtypes.
We attempted to manually configure the aggregates to address the issues we encountered, but unfortunately this did not resolve them.
We would greatly appreciate any guidance or assistance you can offer in resolving these issues. Thank you in advance for your help.
Best regards,
Christiane