DOMAIN_EVENT_ENTRY 表不是由 AXON 创建的

Sum*_*ora 4 spring-data-jpa axon

我的Aggregate礼品卡定义如下,

@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();
    }
}

Run Code Online (Sandbox Code Playgroud)

IssueCardCommand从控制器调度。

public String createGreeting(@PathVariable String cardNumber) {
    IssueCardCommand issueCardCommand = new IssueCardCommand(cardNumber, 100);
    commandGateway.sendAndWait(issueCardCommand, 500L, TimeUnit.MILLISECONDS);
    return "Hey";
}
Run Code Online (Sandbox Code Playgroud)

我可以通过http://localhost:8024/#query在 AxonServer 中查看来确认已调度事件。

我想做 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'
Run Code Online (Sandbox Code Playgroud)

当我在调度事件后查看 h2-console 时,我无法在数据库中找到该事件。很多文章都写过,它将存储在DOMAIN_EVENT_ENTRY表中。不幸的是,就我而言,我找不到那张桌子。我只能看到ASSOCIATION_VALUE_ENTRY, SAGA_ENTRY,TOKEN_ENTRY这 3 个表。

这就是我的设置的样子。命令和事件是为学习/实践目的而编写的(此时您可以忽略业务上下文和最佳实践)

All*_*ard 5

该项目最近更新为仅在实际使用时创建这些表。如果不使用EmbeddedEventStorewith a JPAStorageEngine,则不会创建这些表。在您的设置中,您似乎正在使用 AxonServer(这是默认设置,除非您排除axon-server-connector依赖项)。在这种情况下,事件存储在 AxonServer 中。

所以你看到的是正确的和预期的行为。