GithubHelp home page GithubHelp logo

jianghu50 / tcc-transaction Goto Github PK

View Code? Open in Web Editor NEW

This project forked from changmingxie/tcc-transaction

0.0 1.0 0.0 1.4 MB

tcc-transaction是TCC型事务java实现

License: Apache License 2.0

Java 57.47% FreeMarker 3.13% CSS 36.45% JavaScript 1.86% TSQL 1.09%

tcc-transaction's Introduction

使用指南1.1.x:https://github.com/changmingxie/tcc-transaction/wiki/%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%971.1.x

1.1.x 源码分支:https://github.com/changmingxie/tcc-transaction/tree/master

使用指南1.2.x:https://github.com/changmingxie/tcc-transaction/wiki/%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%971.2.x

1.2.x 源码分支:https://github.com/changmingxie/tcc-transaction/tree/master-1.2.x

1.2.x 版本不向下兼容1.1.x,主要在声明tcc服务方法的注解有改变。1.2.x不同于1.1.x主要的地方在于发布服务时不再强制要求服务方法参数必须有TransactionContext参数,从而减少对业务代码的侵入。

Try: 尝试执行业务

完成所有业务检查(一致性)

预留必须业务资源(准隔离性)

Confirm: 确认执行业务

真正执行业务

不作任何业务检查

只使用Try阶段预留的业务资源

Confirm操作满足幂等性

Cancel: 取消执行业务

释放Try阶段预留的业务资源

Cancel操作满足幂等性

示例说明:

tcc-transaction不和底层使用的rpc框架耦合,也就是使用doubbo,thrift,web service,http等都可。tcc-transaction-http-sample示例演示了不依赖底层rpc框架情况下如何使用tcc-transaction。

在底层rpc框架为dubbo情况下,可利用tcc-trnansaction-dubbo jar提供的便利,方便应用使用tcc-transaction。tcc-transaction-dubbo-sample示例演示了在使用dubbo作为rpc调用情况下如何使用tcc-transaction。

示例演示在下完订单后,使用红包帐户和资金帐户来付款,红包帐户服务和资金帐户服务在不同的系统中。示例中,有两个SOA提供方,一个是CapitalTradeOrderService,代表着资金帐户服务,另一个是RedPacketTradeOrderService,代表着红包帐户服务。

下完订单后,订单状态为DRAFT,在TCC事务中TRY阶段,订单支付服务将订单状态变成PAYING,同时远程调用红包帐户服务和资金帐户服务,将付款方的余额减掉(预留业务资源);如果在TRY阶段,任何一个服务失败,tcc-transaction将自动调用这些服务对应的cancel方法,订单支付服务将订单状态变成PAY_FAILED,同时远程调用红包帐户服务和资金帐户服务,将付款方余额减掉的部分增加回去;如果TRY阶段正常完成,则进入CONFIRM阶段,在CONFIRM阶段(tcc-transaction自动调用),订单支付服务将订单状态变成CONFIRMED,同时远程调用红包帐户服务和资金帐户服务对应的CONFIRM方法,将收款方的余额增加。特别说明下,由于是示例,在CONFIRM和CANCEL方法中没有实现幂等性,如果在真实项目中使用,需要保证CONFIRM和CANCEL方法的幂等性。

在运行sample前,需搭建好db环境,运行dbscripts目录下的create_db.sql建立数据库实例及表;还需修改各种项目中jdbc.properties文件中的jdbc连接信息。

如有问题可以在本项目的github issues中提问。或是加微信:changmingxie,为便于识别,麻烦在备注中写下:名字+所在公司名字+是否线上使用,作者尽量回答疑问。

tcc-transaction's People

Contributors

changmingxie avatar recklessmo avatar code1986 avatar itonyli avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.