Seata TM管理分支事务

发布时间:2024年01月13日

TM相当于一个中间商,是没有涉及到任何数据库底层操作的。

TransactionalTemplate

1、TM向TC端发起一次开启全局事务的请求
io.seata.tm.api.TransactionalTemplate#beginTransaction
-->
io.seata.tm.api.DefaultGlobalTransaction#begin(int, java.lang.String)
-->
io.seata.tm.DefaultTransactionManager#begin
@Override
public String begin(String applicationId, String transactionServiceGroup, String name, int timeout)throws TransactionException {
        GlobalBeginRequest request = new GlobalBeginRequest();
        request.setTransactionName(name);
        request.setTimeout(timeout);
        GlobalBeginResponse response = (GlobalBeginResponse) syncCall(request);
        if (response.getResultCode() == ResultCode.Failed) {
            throw new TmTransactionException(TransactionExceptionCode.BeginFailed, response.getMsg());
        }
        return response.getXid();
}
2、 TM向TC端发起一次全局提交事务请求

io.seata.tm.api.TransactionalTemplate#commitTransaction
-->
io.seata.tm.DefaultTransactionManager#commit
@Override
public GlobalStatus commit(String xid) throws TransactionException {
        GlobalCommitRequest globalCommit = new GlobalCommitRequest();
        globalCommit.setXid(xid);
        GlobalCommitResponse response = (GlobalCommitResponse) syncCall(globalCommit);
        return response.getGlobalStatus();
}
3、TM向TC端发起一次全局回滚事务请求
io.seata.tm.api.TransactionalTemplate#rollbackTransaction
io.seata.tm.DefaultTransactionManager#rollback
    @Override
    public GlobalStatus rollback(String xid) throws TransactionException {
        GlobalRollbackRequest globalRollback = new GlobalRollbackRequest();
        globalRollback.setXid(xid);
        GlobalRollbackResponse response = (GlobalRollbackResponse) syncCall(globalRollback);
        return response.getGlobalStatus();
    }
文章来源:https://blog.csdn.net/lyyCSDNBLOG/article/details/135573295
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。