背景介紹
官網(wǎng)地址: http://seata.io/zh-cn/
sea
原理
image
image
項(xiàng)目集成
image
image
2.集成seata來處理分布式的步驟:
2.1.下載seata_server弯囊,也就是上面說的事務(wù)協(xié)調(diào)器TC绞愚,并進(jìn)行部署眠寿。
(下載地址:https://github.com/seata/seata/releases)
(****在每個(gè)服務(wù)的數(shù)據(jù)庫中建一個(gè)undo表(表名稱在配置中心指定)*****)
2.2.工程中集成(引用組件的三部曲上忍,依賴-配置-注解)
(***注意在調(diào)用鏈中的每個(gè)微服務(wù)都要做集成***)
2.2.1.引入依賴
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-seata</artifactId>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-all</artifactId>
</dependency>
2.2.2.添加配置
registry.conf 對"注冊中心"和"配置中心"設(shè)置
注冊中心:nacos
配置中心:file--》file.conf
file.conf 默認(rèn)的配置中心(文件)
會在里面指定seata服務(wù)的地址
2.2.3.方法上添加注解
主服務(wù)锌半,與各個(gè)子服務(wù)工程的"數(shù)據(jù)源都要交給seata代理"搂抒,"主服務(wù)"使用全局事務(wù)注解@GlobalTransactional,"子服務(wù)"還是使用本地事務(wù)@Transactional臀蛛。
案例下載地址:https://github.com/seata/seata-samples
seata-server部署和配置
下載地址:https://github.com/seata/seata/releases 選擇最新版本亲桦,然后拉到底部點(diǎn)擊下載。
image
啟動服務(wù)
image
工程中的配置
image
image
image
至此浊仆,就將seata集成到了項(xiàng)目中烙肺。
代碼演示
第一步
image
第二步
image
第三步
image
第四步
image
seata與xa的區(qū)別
image