Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated README.md #25

Merged
merged 5 commits into from
Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions README-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
[English](./README.md) | 中文

<p align="center"><a href="https://hyperf.wiki" target="_blank" rel="noopener noreferrer"><img width="70" src="https://img.alicdn.com/imgextra/i1/O1CN011z0JfQ2723QgDiWuH_!!6000000007738-2-tps-1497-401.png" alt="seata Logo"></a></p>

<p align="center">
<a href="https://github.com/seata/seata-php/releases"><img src="https://poser.pugx.org/dtm-php/dtm-client/v/stable" alt="Stable Version"></a>
<a href="https://www.php.net"><img src="https://img.shields.io/badge/php-%3E=8.0-brightgreen.svg?maxAge=2592000" alt="Php Version"></a>
<a href="https://github.com/seata/seata-php/master/LICENSE"><img src="https://img.shields.io/github/license/seata/seata-php.svg" alt="dtm-client License"></a>
</p>
<p align="center">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议用这个格式

![Test case](https://github.com/dtm-php/dtm-client/actions/workflows/test.yml/badge.svg)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样图标无法居中

<a href="https://github.com/seata/seata-php/actions"><img src="https://github.com/seata/seata-php/actions/workflows/test.yml/badge.svg" alt="PHPUnit for Seata-PHP"></a>
<a href="https://packagist.org/packages/seata/seata"><img src="https://poser.pugx.org/seata/seata/downloads" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/seata/seata"><img src="https://poser.pugx.org/seata/seata/d/monthly" alt="Monthly Downloads"></a>
</p>

# 介绍

[Seata](https://github.com/seata/seata) 是一个非常成熟的分布式事务框架,在Java领域是事实上的分布式事务技术标准平台。[Seata-PHP](https://github.com/seata/seata-php) 是 seata 多语言生态中的 PHP 语言实现版本,实现了 Java 和 PHP 之间的互通,让 PHPer 也能使用 Seata-php 来实现分布式事务。

> **在学习 `Seata-PHP`前我们首先来了解一下什么是 `Seata`**

## 什么是 Seata?

一个具有高性能和易用性的**微服务**架构**分布式事务**解决方案。

### 微服务中的分布式事务问题

让我们想象一个传统的单体应用程序。它的业务由3个模块组成。他们使用单一的本地数据源。

自然,数据的一致性将由本地事务来保证。

![Monolithic App](https://img.alicdn.com/imgextra/i3/O1CN01FTtjyG1H4vvVh1sNY_!!6000000000705-0-tps-1106-678.jpg)

微服务架构发生了变化。上面提到的 3 个模块被设计为 3 个不同数据源之上的 3 个服务([Pattern: Database per service](http://microservices.io/patterns/data/database-per-service.html))。 每个服务内的数据一致性自然由本地事务保证。

**但是整个业务逻辑范围呢?**

![Microservices Problem](https://img.alicdn.com/imgextra/i1/O1CN01DXkc3o1te9mnJcHOr_!!6000000005926-0-tps-1268-804.jpg)

### Seata 是怎么做的呢?

Seata 只是上述问题的一个解决方案。

![Seata solution](https://img.alicdn.com/imgextra/i1/O1CN01FheliH1k5VHIRob3p_!!6000000004632-0-tps-1534-908.jpg)

首先,如何定义一个 **分布式事务**?

我们说,**分布式事务** 是由一批分支事务组成的 **全局事务**,而通常 **分支事务** 只是本地事务。

![全局 & 分支](https://cdn.nlark.com/lark/0/2018/png/18862/1545015454979-a18e16f6-ed41-44f1-9c7a-bd82c4d5ff99.png)

在 Seata 框架中,有三个角色。

- **事务协调者(TC):** 维护全局和分支事务的状态,推动全局提交或回滚。

- **事务管理者(TM):** 定义全局事务的范围:开始一个全局事务,提交或回滚一个全局事务

- **资源管理这(RM):** 管理分支事务工作的资源,与TC对话以注册分支事务和报告分支事务的状态,并推动分支事务的提交或回滚。

![模型](https://cdn.nlark.com/lark/0/2018/png/18862/1545013915286-4a90f0df-5fda-41e1-91e0-2aa3d331c035.png)

Seata 管理的分布式事务的一个典型生命周期:

1. TM 要求 TC 开始一个新的全局事务。TC 生成一个代表全局事务的 XID。

2. XID 是通过微服务的调用链传播的。

3. RM 将本地事务登记为 XID 对应的全局事务分支,并提交给 TC。

4. TM 要求 TC 提交或回滚 XID 的相应全局事务。

5. TC 驱动 XID 对应的全局事务下的所有分支事务,完成分支提交或回滚。

![典型流程](https://cdn.nlark.com/lark/0/2018/png/18862/1545296917881-26fabeb9-71fa-4f3e-8a7a-fc317d3389f4.png)

关于原理和设计的更多细节,请访问 [Seata wiki page](https://seata.io/zh-cn/docs/overview/what-is-seata.html)。

## Seata-PHP TODO 列表

- [ ] TCC
- [ ] XA
- [x] AT
- [ ] SAGA
- [x] TM
- [ ] RPC 通信
- [ ] 防悬挂
- [ ] 空回滚
- [ ] 注册中心
- [ ] Metric 监控
- [x] 示例

## 怎样运行 Seata-PHP?

1. 下载服务端 [**seata java**](https://seata.io/zh-cn/blog/download.html) 启动 TC 服务端. 可以参考 [**seata 部署指南**](https://seata.io/zh-cn/docs/ops/deploy-guide-beginner.html) 。

2. 在 [**seata-skeleton**](https://github.com/PandaLIU-1111/seata-skeleton) 环境中运行 Seata-PHP。


## 如何成为贡献者?

Seata-PHP 正处于建设阶段。 欢迎行业同仁入群参与其中,与我们一起推动 Seata-PHP 的建设!如果你想给 Seata-PHP 贡献代码,可以参考 [**code contribution Specification**](./300.contributing/README.md) 文档来了解社区的规范,也可以加入我们的社区钉钉群: 44788115 ,一起沟通交流!

## License

Seata-PHP 使用 Apache 许可证2.0版本,请参阅 [LICENSE 文件](https://github.com/seata/seata-php/blob/master/LICENSE)了解更多。
79 changes: 71 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,80 @@
# Seata-PHP: Simple Extensible Autonomous Transaction Architecture(PHP version)
English | [中文](./README-CN.md)

[![license](https://img.shields.io/github/license/seata/seata-php.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
<p align="center"><a href="https://hyperf.wiki" target="_blank" rel="noopener noreferrer"><img width="70" src="https://img.alicdn.com/imgextra/i1/O1CN011z0JfQ2723QgDiWuH_!!6000000007738-2-tps-1497-401.png" alt="seata Logo"></a></p>

[简体中文 ZH](./docs/zh_cn/README.md)
<p align="center">
<a href="https://github.com/seata/seata-php/releases"><img src="https://poser.pugx.org/dtm-php/dtm-client/v/stable" alt="Stable Version"></a>
<a href="https://www.php.net"><img src="https://img.shields.io/badge/php-%3E=8.0-brightgreen.svg?maxAge=2592000" alt="Php Version"></a>
<a href="https://github.com/seata/seata-php/master/LICENSE"><img src="https://img.shields.io/github/license/seata/seata-php.svg" alt="dtm-client License"></a>
</p>
<p align="center">
<a href="https://github.com/seata/seata-php/actions"><img src="https://github.com/seata/seata-php/actions/workflows/test.yml/badge.svg" alt="PHPUnit for Seata-PHP"></a>
<a href="https://packagist.org/packages/seata/seata"><img src="https://poser.pugx.org/seata/seata/downloads" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/seata/seata"><img src="https://poser.pugx.org/seata/seata/d/monthly" alt="Monthly Downloads"></a>
</p>

## What is Seata-PHP?
# Introduce

Seata is a very mature distributed transaction framework, and is the de facto standard platform for distributed transaction technology in the Java field. Seata-PHP is the implementation version of PHP language in Seata multilingual ecosystem, which realizes the interoperability between Java and PHP, so that PHP developers can also use Seata-PHP to realize distributed transactions. Please visit the [official website of Seata](https://seata.io/en-us) to view the quick start and documentation.
[Seata](https://github.com/seata/seata) is a very mature distributed transaction framework, and is the de facto standard platform for distributed transaction technology in the Java field. [Seata-PHP](https://github.com/seata/seata-php) is the implementation version of PHP language in Seata multilingual ecosystem, which realizes the interoperability between Java and PHP, so that PHP developers can also use Seata-PHP to realize distributed transactions.

The principle of Seata-PHP is consistent with that of Seata-Java, which is composed of TM, RM and TC. The functions of TC reuse Java, and the functions of TM and RM will be aligned with Seata-Java later. The overall process is as follows:
> **Before learning about the ` Seata-PHP `, let's first understand what's the ` Seata `**

![](https://user-images.githubusercontent.com/68344696/145942191-7a2d469f-94c8-4cd2-8c7e-46ad75683636.png)
## What is Seata?

## TODO list
A **distributed transaction solution** with high performance and ease of use for **microservices** architecture.
### Distributed Transaction Problem in Microservices

Let's imagine a traditional monolithic application. Its business is built up with 3 modules. They use a single local data source.

Naturally, data consistency will be guaranteed by the local transaction.

![Monolithic App](https://img.alicdn.com/imgextra/i3/O1CN01FTtjyG1H4vvVh1sNY_!!6000000000705-0-tps-1106-678.jpg)

Things have changed in a microservices architecture. The 3 modules mentioned above are designed to be 3 services on top of 3 different data sources ([Pattern: Database per service](http://microservices.io/patterns/data/database-per-service.html)). Data consistency within every single service is naturally guaranteed by the local transaction.

**But how about the whole business logic scope?**

![Microservices Problem](https://img.alicdn.com/imgextra/i1/O1CN01DXkc3o1te9mnJcHOr_!!6000000005926-0-tps-1268-804.jpg)

### How Seata do?

Seata is just a solution to the problem mentioned above.

![Seata solution](https://img.alicdn.com/imgextra/i1/O1CN01FheliH1k5VHIRob3p_!!6000000004632-0-tps-1534-908.jpg)

Firstly, how to define a **Distributed Transaction**?

We say, a **Distributed Transaction** is a **Global Transaction** which is made up with a batch of **Branch Transaction**, and normally **Branch Transaction** is just **Local Transaction**.

![Global & Branch](https://cdn.nlark.com/lark/0/2018/png/18862/1545015454979-a18e16f6-ed41-44f1-9c7a-bd82c4d5ff99.png)

There are three roles in Seata Framework:

- **Transaction Coordinator(TC):** Maintain status of global and branch transactions, drive the global commit or rollback.

- **Transaction Manager(TM):** Define the scope of global transaction: begin a global transaction, commit or rollback a global transaction.

- **Resource Manager(RM):** Manage resources that branch transactions working on, talk to TC for registering branch transactions and reporting status of branch transactions, and drive the branch transaction commit or rollback.

![Model](https://cdn.nlark.com/lark/0/2018/png/18862/1545013915286-4a90f0df-5fda-41e1-91e0-2aa3d331c035.png)

A typical lifecycle of Seata managed distributed transaction:

1. TM asks TC to begin a new global transaction. TC generates an XID representing the global transaction.

2. XID is propagated through microservices' invoke chain.

3. RM registers local transaction as a branch of the corresponding global transaction of XID to TC.

4. TM asks TC for committing or rollbacking the corresponding global transaction of XID.

5. TC drives all branch transactions under the corresponding global transaction of XID to finish branch committing or rollbacking.

![Typical Process](https://cdn.nlark.com/lark/0/2018/png/18862/1545296917881-26fabeb9-71fa-4f3e-8a7a-fc317d3389f4.png)

For more details about principle and design, please go to [Seata wiki page](https://seata.io/en-us/docs/overview/what-is-seata.html).

## Seata-PHP TODO List

- [ ] TCC
- [ ] XA
Expand All @@ -30,6 +92,7 @@ The principle of Seata-PHP is consistent with that of Seata-Java, which is compo
## How to run?

1. First download [**seata java**](https://seata.io/zh-cn/blog/download.html) and Start the TC service. For the specific process, refer to [**seata deployment guide**](https://seata.io/zh-cn/docs/ops/deploy-guide-beginner.html) Documentation

2. Run seata-php whith [**seata-skeleton**](https://github.com/PandaLIU-1111/seata-skeleton)


Expand Down