DOMAIN_EVENT_ENTRY table 不是 AXON 创建的

DOMAIN_EVENT_ENTRY table is not created by AXON

我的 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_ENTRYtable。不幸的是,就我而言,我无法找到 table。我只能看到ASSOCIATION_VALUE_ENTRYSAGA_ENTRYTOKEN_ENTRY这3个table。

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

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

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