[Seata] 之 初識

這邊採取SpringCloud-JPA-Seata來測試

按照:https://github.com/seata/seata-samples/tree/master/springcloud-jpa-seata

一 準備工作



(1)執行SQL

springcloud-jpa-seata目錄下有sql/all_in_one.sql,可直接執行


(2)下載Seata Sever,並運行

下載地址:https://github.com/seata/seata/releases

這邊下載最新版本:0.7.1

// zip文件
unzip seata-server-xxx.zip

// tar.gz
tar -zxvf seata-server.ta.gz -C seata-server

sh ./bin/seata-server.sh -p 8091  -m file

啓動後如下:

在這裏插入圖片描述


(3)更改項目配置

例如account-service服務,打開application.properties

按照自己實際的配置更新,比如:

spring.datasource.url=jdbc:mysql://localhost:3306/db_account?useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root

(4)啓動服務

啓動account-service busniess-service order-service storage-service 服務

在這裏插入圖片描述



二 測試



(1)無錯誤,成功提交

  1. 請求訪問
    curl http://127.0.0.1:8084/purchase/commit

在這裏插入圖片描述

  1. account_tblid = 1money減少5

在這裏插入圖片描述

  1. storage_tblid = 1count減少1

在這裏插入圖片描述
在這裏插入圖片描述

(2)發生異常,事務回滾

  1. 請求訪問
    curl http://127.0.0.1:8084/purchase/rollback

在這裏插入圖片描述

  1. account-service拋出異常

  2. business-service捕獲異常

在這裏插入圖片描述

  1. seata server顯示

在這裏插入圖片描述
在這裏插入圖片描述



三 問題


(1)數據庫中undo_log什麼時候會有記錄呢?

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章