用AI赚第一桶💰低成本搭建一套AI赚钱工具,源码可二开。 广告
## Saga 多库事务实现 Beetl的 Saga基于Spring Boot 引入SpringBoot的BeetlSQL Starter,以及Saga Local ```xml <dependency> <groupId>com.ibeetl</groupId> <artifactId>sql-springboot-starter</artifactId> <version>${version}</version> </dependency> <dependency> <groupId>com.ibeetl</groupId> <artifactId>sql-saga-local</artifactId> <version>${version}</version> </dependency> ``` 系统初始化地方设置Saga Local实现,通常是一个Spring Boot的 Configration的配置类里完成 ```java SagaContext.sagaContextFactory = new LocalSagaContextFactory(); ``` 这样代码`SagaContext.sagaContextFactory.current()`返回的是一个`LocalSagaContext`,此类实现了Saga事务管理,使用如下模板即可实现多库的Saga事务管理 ```java SagaContext sagaContext = SagaContext.sagaContextFactory.current(); try{ sagaContext.start(); //任何操作,或者是调用嵌套Saga事务的其他代码 sagaContext.commit(); }(Exception ex){ sagaContext.rollback(); } ```