- TCC 基于RM本地事务来实现
https://github.com/liuyangming/ByteTCC 源码分析: 1.1.1. Spring Cloud <dependency> <groupId>org.bytesoft</groupId> <artifactId>bytetcc-supports-springcloud</artifactId> <version>0.5.7</version> </dependency> 1.1.2. dubbo <dependency> <groupId>org.bytesoft</groupId> <artifactId>bytetcc-supports-dubbo</artifactId> <version>0.5.7</version> </dependency> 1.2 Compose a business service @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 Compose a confirm service @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 Compose a cancel service @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); } }
- sega
来源:CSDN
作者:龙仔1984
链接:https://blog.csdn.net/ma_ru_long/article/details/103976786