Skip to content

Commit 1e28af5

Browse files
add jpa event store config
1 parent 995e4c4 commit 1e28af5

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,8 @@ void givenDwellingWith2Creatures_WhenRecruit2Creatures_ThenRecruited() {
158158
If you'd like to hire me for Domain-Driven Design and/or Event Sourcing projects I'm available to work with:
159159
Kotlin, Java, C# .NET, Ruby and JavaScript/TypeScript (Node.js or React).
160160
Please reach me out on LinkedIn [linkedin.com/in/mateusznakodach/](https://www.linkedin.com/in/mateusznakodach/).
161+
162+
163+
### Helpful:
164+
CHECK snapshot content!
165+
```TO read snapshot data: SELECT lo_get(18333) AS payload;```

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@
1919
import org.axonframework.modelling.command.AggregateIdentifier;
2020
import org.axonframework.modelling.command.CreationPolicy;
2121
import org.axonframework.spring.stereotype.Aggregate;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
2224

2325
import static org.axonframework.modelling.command.AggregateLifecycle.*;
2426

2527
@Aggregate(snapshotTriggerDefinition = "dwellingSnapshotTrigger")
2628
public class Dwelling {
2729

30+
private static final Logger logger = LoggerFactory.getLogger(Dwelling.class);
31+
2832
@AggregateIdentifier
2933
public DwellingId dwellingId;
3034
public CreatureId creatureId;
@@ -47,6 +51,7 @@ void decide(BuildDwelling command) {
4751

4852
@EventSourcingHandler
4953
void evolve(DwellingBuilt event) {
54+
logger.info("🏗️ Dwelling built with ID: {}, creature type: {}", event.dwellingId(), event.creatureId());
5055
this.dwellingId = new DwellingId(event.dwellingId());
5156
this.creatureId = new CreatureId(event.creatureId());
5257
this.costPerTroop = Resources.fromRaw(event.costPerTroop());
@@ -69,6 +74,8 @@ void decide(IncreaseAvailableCreatures command) {
6974

7075
@EventSourcingHandler
7176
void evolve(AvailableCreaturesChanged event) {
77+
logger.info("📈 Available creatures changed for dwelling {}: {} creatures now available",
78+
event.dwellingId(), event.changedTo());
7279
this.availableCreatures = new Amount(event.changedTo());
7380
}
7481

@@ -104,11 +111,14 @@ void decide(RecruitCreature command) {
104111

105112
@EventSourcingHandler
106113
void evolve(CreatureRecruited event) {
114+
logger.info("🧙 Recruited {} creatures of type {} from dwelling {} to army {}",
115+
event.quantity(), event.creatureId(), event.dwellingId(), event.toArmy());
107116
// todo: consider if it's OK or RecruitCreature should cause also AvailableCreaturesChanged event
108117
this.availableCreatures = this.availableCreatures.minus(new Amount(event.quantity()));
109118
}
110119

111120
Dwelling() {
121+
logger.info("🏠 Creating empty Dwelling (required by Axon)");
112122
// required by Axon
113123
}
114124
}

0 commit comments

Comments
 (0)