axon - Axon 4 - JVM 重启后 Saga 再次运行
问题描述
我将 Axon4 与 Spring Boot 一起使用。创造了简单的传奇。它在运行中的 JVM 期间运行良好。但是,一旦重新启动,它就会再次重新运行 Saga。
试图对 JpaSagaStore 进行持久性,但没有奏效。下面是代码片段。请帮忙。
@Configuration
public class AxonConfig {
@PersistenceContext
private EntityManager entityManager;
@Bean
public SagaStore sagaStore() {
return JpaSagaStore.builder().entityManagerProvider(new SimpleEntityManagerProvider(entityManager)).build();
}
}
@Saga(sagaStore = "sagaStore")
@Slf4j
public class OrderSaga {
@Autowired
private transient CommandGateway commandGateway;
private UUID orderId;
private boolean passed;
@StartSaga
@SagaEventHandler(associationProperty = "orderId")
public void on(OrderPlacedEvt evt) {
log.debug("handling {}", evt);
if (!passed) {
orderId = evt.getOrderId();
UUID shipmentId = UUID.randomUUID();
associateWith("shipmentId", shipmentId.toString());
commandGateway.send(new PrepareShipmentCmd(shipmentId, evt.getDestination()));
}
}
@SagaEventHandler(associationProperty = "shipmentId")
public void on(ShipmentPreparedEvt evt) {
log.debug("handling {}", evt);
log.debug("orderId: {}", orderId);
commandGateway.send(new RegisterShipmentForOrderPreparedCmd(orderId, evt.getShipmentId()));
}
@SagaEventHandler(associationProperty = "shipmentId")
@EndSaga
public void on(ShipmentArrivedEvt evt) {
log.debug("handling {}", evt);
log.debug("orderId: {}", orderId);
commandGateway.send(new RegisterShipmentForOrderArrivedCmd(orderId, evt.getShipmentId()));
}
}
解决方案
对Prashant他的问题的决议在这里进一步讨论
简而言之,数据库create
在每次启动时设置为。因此,跟踪 Saga 处理事件的距离的令牌(用于跟踪事件处理器)在应用程序的每次启动时被重置。
因此切换线路spring.jpa.properties.hibernate.hbm2ddl.auto=create
以spring.jpa.properties.hibernate.hbm2ddl.auto=update
解决问题。
推荐阅读
- g++ - 我不断收到“'g++' 未被识别为内部或外部命令、可运行程序或批处理文件。” 输入 g++ --version 后出错
- css - 全高顺风
部分 - php - 卷曲到 GuzzleHttp
- python - 使用 Dropbox API 将 PNG 从 python 保存到 Dropbox
- node.js - 使用 Npm 将 framework7 安装到科尔多瓦时出错
- javascript - 使用 Navlink Router 和 Switch Route 链接网站
- vue.js - Vue 3 相当于 createApp 中的 beforeMount
- javascript - HTML 视频元素从单个视频播放多个音轨
- marketo - 使用带有 Marketo 活动批量提取 API 的过滤器类型 UpdatedAt
- algorithm - 如何推导出大 O 符号?