Skip to content

Commit d9fa063

Browse files
📸 chore: Creature Recruitment | Add snapshotting to Dwelling aggregate with 5-event threshold
The Dwelling aggregate is now configured to use the existing dwellingSnapshotTrigger bean to create snapshots every 5 events. It's just to show how the snapshotting can be configured.
1 parent f344304 commit d9fa063

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎src/main/java/com/dddheroes/heroesofddd/creaturerecruitment/CreatureRecruitmentConfiguration.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import com.dddheroes.heroesofddd.creaturerecruitment.write.recruitcreature.RecruitCreature;
44
import com.dddheroes.heroesofddd.resourcespool.application.CommandCostResolver;
55
import com.dddheroes.heroesofddd.shared.domain.valueobjects.Resources;
6+
import org.axonframework.eventsourcing.EventCountSnapshotTriggerDefinition;
7+
import org.axonframework.eventsourcing.SnapshotTriggerDefinition;
8+
import org.axonframework.eventsourcing.Snapshotter;
69
import org.springframework.context.annotation.Bean;
710
import org.springframework.context.annotation.Configuration;
811

@@ -23,4 +26,9 @@ public Class<? extends RecruitCreature> supportedCommandType() {
2326
}
2427
};
2528
}
29+
30+
@Bean
31+
SnapshotTriggerDefinition dwellingSnapshotTrigger(Snapshotter snapshotter) {
32+
return new EventCountSnapshotTriggerDefinition(snapshotter, 5);
33+
}
2634
}

‎src/main/java/com/dddheroes/heroesofddd/creaturerecruitment/write/Dwelling.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import static org.axonframework.modelling.command.AggregateLifecycle.*;
2424

25-
@Aggregate
25+
@Aggregate(snapshotTriggerDefinition = "dwellingSnapshotTrigger")
2626
public class Dwelling {
2727

2828
@AggregateIdentifier

0 commit comments

Comments
 (0)