ByteTCC分布式事務管理器
ByteTCC是一個基于TCC(Try/Confirm/Cancel)機制的分布式事務管理器。兼容JTA,可以很好的與Spring容器進行集成。
一、快速入門
1.1. 加入maven依賴
1.1.1. 使用Spring Cloud
<dependency> <groupId>org.bytesoft</groupId> <artifactId>bytetcc-supports-springcloud</artifactId> <version>0.4.0-rc1</version> </dependency>
1.1.1. 使用Dubbo
<dependency> <groupId>org.bytesoft</groupId> <artifactId>bytetcc-supports-dubbo</artifactId> <version>0.4.0-rc1</version> </dependency>
1.2. 編寫業(yè)務服務
@Service("accountService")
@Compensable(
interfaceClass = IAccountService.class
, confirmableKey = "accountServiceConfirm"
, cancellableKey = "accountServiceCancel"
)
public class AccountServiceImpl implements IAccountService {
@Resource(name = "jdbcTemplate")
private JdbcTemplate jdbcTemplate;
@Transactional
public void increaseAmount(String accountId, double amount) throws ServiceException {
this.jdbcTemplate.update("update tb_account set frozen = frozen + ? where acct_id = ?", amount, acctId);
}
}
1.3. 編寫confirm服務
@Service("accountServiceConfirm")
public class AccountServiceConfirm implements IAccountService {
@Resource(name = "jdbcTemplate")
private JdbcTemplate jdbcTemplate;
@Transactional
public void increaseAmount(String accountId, double amount) throws ServiceException {
this.jdbcTemplate.update("update tb_account set amount = amount + ?, frozen = frozen - ? where acct_id = ?", amount, amount, acctId);
}
}
1.4. 編寫cancel服務
@Service("accountServiceCancel")
public class AccountServiceCancel implements IAccountService {
@Resource(name = "jdbcTemplate")
private JdbcTemplate jdbcTemplate;
@Transactional
public void increaseAmount(String accountId, double amount) throws ServiceException {
this.jdbcTemplate.update("update tb_account set frozen = frozen - ? where acct_id = ?", amount, acctId);
}
}
二、文檔 & 樣例
* 使用文檔: https://github.com/liuyangming/ByteTCC/wiki
* 使用樣例: https://github.com/liuyangming/ByteTCC-sample
三、ByteTCC特性
* 1、支持Spring容器的聲明式事務管理;
* 2、支持普通事務、TCC事務、業(yè)務補償型事務等事務機制;
* 3、支持多數(shù)據(jù)源、跨應用、跨服務器等分布式事務場景;
* 4、支持長事務;
* 5、支持dubbo服務框架;
* 6、支持spring-cloud;
四、服務質(zhì)量
4.1. 故障恢復
任意時刻因任意故障(包括但不限于:業(yè)務系統(tǒng)/RDBS服務器宕機;網(wǎng)絡故障;斷電等)造成的事務中斷,ByteTCC均有相應機制予以恢復,保證全局事務的最終一致性。
4.2. 冪等性
ByteTCC在框架層面提供對Confirm/Cancel業(yè)務邏輯的冪等性保障,業(yè)務系統(tǒng)僅需關注自身業(yè)務本身,無需為冪等性問題而煩惱。
五、建議及改進
若您有任何建議,可以通過1)加入qq群537445956/606453172向群主提出,或2)發(fā)送郵件至[email protected]向我反饋。本人承諾,任何建議都將會被認真考慮,優(yōu)秀的建議將會被采用,但不保證一定會在當前版本中實現(xiàn)。
評論
圖片
表情
