【发布时间】:2019-04-16 10:51:50
【问题描述】:
我的 Aggregate GiftCard 定义如下,
@Data
@NoArgsConstructor
@Aggregate
public class GiftCard {
@AggregateIdentifier
private String id;
private int remainingValue;
@CommandHandler
public GiftCard(IssueCardCommand cmd) {
apply(new CardIssuedEvent(cmd.getCardId(), cmd.getAmount()));
}
@CommandHandler
public GiftCard(TempCommand cmd) {
apply(new CardIssuedEvent(cmd.getCardId(), cmd.getAmount()));
}
@EventSourcingHandler
public void on(CardIssuedEvent event) {
this.id = event.getCardId();
this.remainingValue = event.getAmount();
}
}
我从控制器发送IssueCardCommand。
public String createGreeting(@PathVariable String cardNumber) {
IssueCardCommand issueCardCommand = new IssueCardCommand(cardNumber, 100);
commandGateway.sendAndWait(issueCardCommand, 500L, TimeUnit.MILLISECONDS);
return "Hey";
}
我可以通过查看 AxonServer 中的 http://localhost:8024/#query 来确认事件已发送。
我想做 EventSourcing 并设置了内存 H2 数据库。
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.6'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.3.RELEASE'
implementation 'org.axonframework:axon:4.1.1'
implementation 'org.axonframework:axon-spring-boot-starter:4.1.1'
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.1.4.RELEASE'
runtime group: 'com.h2database', name: 'h2', version: '1.4.199'
当我在调度事件后查看 h2-console 时,我无法在数据库中找到该事件。很多文章都写过,它将存储在DOMAIN_EVENT_ENTRY表中。不幸的是,就我而言,我找不到那张桌子。我只能看到ASSOCIATION_VALUE_ENTRY、SAGA_ENTRY、TOKEN_ENTRY这3张表。
这就是我的设置的样子。命令和事件是为学习/实践目的而编写的(此时您可以忽略业务上下文和最佳实践)
【问题讨论】:
标签: spring-data-jpa axon