ByteTCC分布式事務(wù)管理器
ByteTCC是一個基于TCC(Try/Confirm/Cancel)機制的分布式事務(wù)管理器。兼容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è)務(wù)服務(wù)
@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服務(wù)
@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服務(wù)
@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容器的聲明式事務(wù)管理;
* 2、支持普通事務(wù)、TCC事務(wù)、業(yè)務(wù)補償型事務(wù)等事務(wù)機制;
* 3、支持多數(shù)據(jù)源、跨應(yīng)用、跨服務(wù)器等分布式事務(wù)場景;
* 4、支持長事務(wù);
* 5、支持dubbo服務(wù)框架;
* 6、支持spring-cloud;
四、服務(wù)質(zhì)量
4.1. 故障恢復
任意時刻因任意故障(包括但不限于:業(yè)務(wù)系統(tǒng)/RDBS服務(wù)器宕機;網(wǎng)絡(luò)故障;斷電等)造成的事務(wù)中斷,ByteTCC均有相應(yīng)機制予以恢復,保證全局事務(wù)的最終一致性。
4.2. 冪等性
ByteTCC在框架層面提供對Confirm/Cancel業(yè)務(wù)邏輯的冪等性保障,業(yè)務(wù)系統(tǒng)僅需關(guān)注自身業(yè)務(wù)本身,無需為冪等性問題而煩惱。
五、建議及改進
若您有任何建議,可以通過1)加入qq群537445956/606453172向群主提出,或2)發(fā)送郵件至[email protected]向我反饋。本人承諾,任何建議都將會被認真考慮,優(yōu)秀的建議將會被采用,但不保證一定會在當前版本中實現(xiàn)。
評論
圖片
表情
