【问题标题】:Retrieval of data from domainevententry table based on particular event using Axonframework使用 Axonframework 基于特定事件从 domainevententry 表中检索数据
【发布时间】:2017-05-22 08:47:44
【问题描述】:
我正在构建一个 Web 应用程序,我需要在其中跟踪一些事件,例如 sms 发送、传递或失败。为此,我想使用 Axonframework 。我已经关注了官方网站上的axonframework教程,也来自this website
但我没有找到任何解决方案来从 Axon 本身创建的 daomainevententry 表中获取事件。我正在使用 Java 语言、Spring 框架和 MySql 数据库来完成我的应用程序的开发。
请告诉我任何好的教程或解决方案。
【问题讨论】:
标签:
java
spring-boot
axon
【解决方案1】:
如果您使用JpaEventStorageEngine(例如,您的类路径中有spring-data-jpa,并使用application.properties 或application.yml 配置了JPA 持久性单元),Axon 将使用实体DomainEventEntry 来存储事件。在您的数据库中,这些结果会出现在表 DOMAIN_EVENT_ENTRY 或类似的条目中。
要从 Spring 访问它,您可以自己使用 Spring-Data。定义一个 Spring-Data 存储库:
import org.axonframework.eventsourcing.eventstore.jpa.DomainEventEntry;
import org.springframework.data.jpa.repository.JpaRepository;
public interface DomainEventRepository extends JpaRepository<DomainEventEntry, Long> {
}
通过这样做,您将获得从该存储库查询的默认访问方法。对于进一步的定制,您可以编写其他方法。具体操作方法请咨询documentation of Spring Data。
您可能有兴趣查询某个聚合的事件:
List<DomainEventEntry> findByAggregateIdentifier(String aggregateIdentifier);
或按特定类型:
List<DomainEventEntry> findByType(String type);
要探索更多信息,只需浏览 DomainEventEntry 的层次结构并寻找有趣的字段。
希望这会有所帮助,
西蒙