Download the PHP package wangrunxinyes/hyperf-tcc without Composer
On this page you can find all versions of the php package wangrunxinyes/hyperf-tcc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download wangrunxinyes/hyperf-tcc
More information about wangrunxinyes/hyperf-tcc
Files in wangrunxinyes/hyperf-tcc
Download wangrunxinyes/hyperf-tcc
More information about wangrunxinyes/hyperf-tcc
Files in wangrunxinyes/hyperf-tcc
Vendor wangrunxinyes
Package hyperf-tcc
Short Description 基于Hyperf框架的TCC分布式事务组件
License MIT
Homepage https://github.com/yogcloud/hyperf-tcc
Package hyperf-tcc
Short Description 基于Hyperf框架的TCC分布式事务组件
License MIT
Homepage https://github.com/yogcloud/hyperf-tcc
Please rate this library. Is it a good library?
Informations about the package hyperf-tcc
hyperf-tcc
基于 Hyperf 框架的分布式事务 TCC 组件
-Fork version -Original: https://github.com/YogCloud/hyperf-tcc -Use rabbitmq instead of Nsq
Install
在使用 tcc 前先确保已经安装 Redis, Rabbitmq
发布资源
执行迁移
Run
Test
Benchmark
注意事项
- 分布式事务, 本身是为了确保数据一致性, 在高并发测试下, 应该对接口服务做好限流(使用
RateLimit
组件)
功能列表
- [X] 实现TCC操作实现接口
TccOption
- [X] 实现事务处理
Tcc
- [X] 实现事务编排
Tcc->rely(...)
- [X] 实现事务重试
NSQ消息订阅
- [X] 实现无法回滚事务记录并通知
Database
Composer依赖
"hyperf/redis": "~2.1.0"
"hyperf/database": "~2.1.0"
"hyperf/snowflake": "^2.1"
"hyperf/logger": "~2.1.0"
"hyperf/db-connection": "~2.1.0"
使用方式
Tcc
事务创建- 对于事务进行流程编排
- 对于事务的启动操作
TccOption
事务操作- 需要针对性实现
try, confirm, cancel
方法 - 例如
商品库存锁定
,商品库存扣除
等 - 在
YogCloud\TccTransaction\Example\Tcc
下能看到很多演示写法 - 不应当把
复杂的参数
放到该类中去例如对象等, 因为它会作为一个序列化的类
存放到redis
中 - 如果操作类
参数过多
, 或者属性
中对象过多
会造成存储负担
- 不推荐在
TccOption
操作类中写业务逻辑, 它应当作为一个调用服务的封装
- 需要针对性实现
TccState
事务状态- 存放操作和状态并且序列化到缓存中
Coordinator/TccCoordinator
事务协调者NSQ消费者
需要加入到消费进程- 请先继承该类实现
NSQ消费者进程绑定 @Consumer 注解
- 具体查看 Hyperf NSQ文档
- 请先继承该类实现
代码演示
- 下面的代码演示都在
Example
中有实现 Example\Tcc\*
事务操作项Example\Service\*
微服务实现类Example\Test
模拟下单接口Example\database.sql
演示案例数据库脚本, 测试前先导入
实现原理
TccOption
都必须实现try, confirm, cancel
方法-
其中
confirm
允许空操作
All versions of hyperf-tcc with dependencies
PHP Build Version
Package Version
Requires
hyperf/nsq Version
~2.1 | 2.2.*
hyperf/redis Version ~2.1 | 2.2.*
hyperf/database Version ~2.1 | 2.2.*
hyperf/snowflake Version ~2.1 | 2.2.*
hyperf/logger Version ~2.1 | 2.2.*
hyperf/db-connection Version ~2.1 | 2.2.*
hyperf/redis Version ~2.1 | 2.2.*
hyperf/database Version ~2.1 | 2.2.*
hyperf/snowflake Version ~2.1 | 2.2.*
hyperf/logger Version ~2.1 | 2.2.*
hyperf/db-connection Version ~2.1 | 2.2.*
The package wangrunxinyes/hyperf-tcc contains the following files
Loading the files please wait ....