Skip to content

Commit

Permalink
Added install docs
Browse files Browse the repository at this point in the history
  • Loading branch information
PandaLIU-1111 committed Jul 7, 2024
1 parent 9540bff commit b58999f
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 118 deletions.
81 changes: 81 additions & 0 deletions Docs/install-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# 安装指南

## 在 Hyperf 框架下的安装

### 如何安装

通过 Composer 快速安装 `dtm-client`

```bash
composer require dtm/dtm-client
```

*使用前请确保 DTM Server 已启动。*

### 配置步骤

#### 配置文件

Hyperf 框架用户,在安装后,使用以下命令发布配置文件至 `./config/autoload/dtm.php`

```bash
php bin/hyperf.php vendor:publish dtm/dtm-client
```

非 Hyperf 用户,将配置文件从 `./vendor/dtm/dtm-client/publish/dtm.php` 复制到您的配置目录。

```php
use DtmClient\Constants\Protocol;
use DtmClient\Constants\DbType;

return [
// 客户端与 DTM 服务器间的通信协议,支持 Protocol::HTTP 和 Protocol::GRPC
'protocol' => Protocol::HTTP,
// DTM 服务器地址
'server' => '127.0.0.1',
// DTM 服务器端口
'port' => [
'http' => 36789,
'grpc' => 36790,
],
// 子事务屏障设置
'barrier' => [
// 数据库模式下的子事务屏障设置
'db' => [
'type' => DbType::MySQL
],
// Redis 模式下的子事务屏障设置
'redis' => [
// 子事务屏障记录的超时时间
'expire_seconds' => 7 * 86400,
],
// 在 Hyperf 外应用子事务屏障的类
'apply' => [],
],
// HTTP 协议下 Guzzle 客户端的通用配置
'guzzle' => [
'options' => [],
],
];
```

#### 中间件配置

使用前,需将 `DtmClient\Middleware\DtmMiddleware` 配置为服务器的全局中间件。该中间件符合 PSR-15 标准,适用于所有支持此标准的框架。
Hyperf 中的中间件配置请参见 [Hyperf 文档 - 中间件](https://www.hyperf.wiki/2.2/#/zh-cn/middleware/middleware)

#### 使用 json-rpc-http 协议

若项目需使用 json-rpc 协议,请在配置文件中将 `protocol` 设置为 `Protocol::JSONRPC_HTTP`,并在 `config/autoload/dependencies.php` 中配置依赖。

```php
use DtmClient\JsonRpc\DtmPathGenerator;
use Hyperf\JsonRpc\JsonRpcPoolTransporter;
use Hyperf\JsonRpc\JsonRpcTransporter;
use Hyperf\Rpc\Contract\PathGeneratorInterface;

return [
PathGeneratorInterface::class => DtmPathGenerator::class,
JsonRpcTransporter::class => JsonRpcPoolTransporter::class,
];
```
81 changes: 81 additions & 0 deletions Docs/install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Installation

## Installing with the Hyperf Framework

### How to Install

Install the `dtm-client` easily via Composer:

```bash
composer require dtm/dtm-client
```

*Remember to start the DTM Server before using it.*

### Configuration Steps

#### Configuration File

For Hyperf framework users, after installation, publish the configuration file to `./config/autoload/dtm.php` using the command below:

```bash
php bin/hyperf.php vendor:publish dtm/dtm-client
```

For non-Hyperf users, copy the configuration file from `./vendor/dtm/dtm-client/publish/dtm.php` to your configuration directory.

```php
use DtmClient\Constants\Protocol;
use DtmClient\Constants\DbType;

return [
// Communication protocol between client and DTM Server, supports Protocol::HTTP and Protocol::GRPC
'protocol' => Protocol::HTTP,
// DTM Server address
'server' => '127.0.0.1',
// DTM Server ports
'port' => [
'http' => 36789,
'grpc' => 36790,
],
// Sub-transaction barrier settings
'barrier' => [
// DB mode sub-transaction barrier settings
'db' => [
'type' => DbType::MySQL
],
// Redis mode sub-transaction barrier settings
'redis' => [
// Timeout for sub-transaction barrier records
'expire_seconds' => 7 * 86400,
],
// Classes for applying sub-transaction barriers outside of Hyperf
'apply' => [],
],
// General Guzzle client configuration for HTTP protocol
'guzzle' => [
'options' => [],
],
];
```

#### Middleware Configuration

Configure `DtmClient\Middleware\DtmMiddleware` as the global middleware for your server before use. This middleware is PSR-15 compliant and compatible with any framework supporting this standard.
For middleware setup in Hyperf, see the [Hyperf Documentation - Middleware](https://www.hyperf.wiki/2.2/#/en/middleware/middleware).

#### Using the json-rpc-http Protocol

To use the json-rpc protocol in your project, set `protocol` to `Protocol::JSONRPC_HTTP` in the configuration file and configure dependencies in `config/autoload/dependencies.php`.

```php
use DtmClient\JsonRpc\DtmPathGenerator;
use Hyperf\JsonRpc\JsonRpcPoolTransporter;
use Hyperf\JsonRpc\JsonRpcTransporter;
use Hyperf\Rpc\Contract\PathGeneratorInterface;

return [
PathGeneratorInterface::class => DtmPathGenerator::class,
JsonRpcTransporter::class => JsonRpcPoolTransporter::class,
];
```
60 changes: 1 addition & 59 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,65 +56,7 @@ DTM 是一款基于 Go 语言实现的开源分布式事务管理器,提供跨

# 安装

通过 Composer 可以非常方便的安装 dtm-client

```bash
composer require dtm/dtm-client
```

* 使用时别忘了启动 DTM Server 哦

# 配置

## 配置文件

如果您是在 Hyperf 框架中使用,在安装组件后,可通过下面的 `vendor:publish` 命令一件发布配置文件于 `./config/autoload/dtm.php`

```bash
php bin/hyperf.php vendor:publish dtm/dtm-client
```

如果您是在非 Hyperf 框架中使用,可复制 `./vendor/dtm/dtm-client/publish/dtm.php` 文件到对应的配置目录中。

```php
use DtmClient\Constants\Protocol;
use DtmClient\Constants\DbType;

return [
// 客户端与 DTM Server 通讯的协议,支持 Protocol::HTTP 和 Protocol::GRPC 两种
'protocol' => Protocol::HTTP,
// DTM Server 的地址
'server' => '127.0.0.1',
// DTM Server 的端口
'port' => [
'http' => 36789,
'grpc' => 36790,
],
// 子事务屏障配置
'barrier' => [
// DB 模式下的子事务屏障配置
'db' => [
'type' => DbType::MySQL
],
// Redis 模式下的子事务屏障配置
'redis' => [
// 子事务屏障记录的超时时间
'expire_seconds' => 7 * 86400,
],
// 非 Hyperf 框架下应用子事务屏障的类
'apply' => [],
],
// HTTP 协议下 Guzzle 客户端的通用配置
'guzzle' => [
'options' => [],
],
];
```

## 配置中间件

在使用之前,需要配置 `DtmClient\Middleware\DtmMiddleware` 中间件作为 Server 的全局中间件,该中间件支持 PSR-15 规范,可适用于各个支持该规范的的框架。
在 Hyperf 中的中间件配置可参考 [Hyperf文档 - 中间件](https://www.hyperf.wiki/2.2/#/zh-cn/middleware/middleware) 一章。
[安装指南](/Docs/install-CN.md)

# 使用

Expand Down
60 changes: 1 addition & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,65 +56,7 @@ From the characteristics of the comparison above, DTM has great advantages in ma

# Installation

It is very convenient to install dtm-client through Composer

```bash
composer require dtm/dtm-client
```

* Don't forget to start DTM Server before you use it

# Configuration

## Configuration file

If you are using the Hyperf framework, after installing the component, you can publish a configuration file to `./config/autoload/dtm.php` with the following `vendor:publish` command

```bash
php bin/hyperf.php vendor:publish dtm/dtm-client
```

If you are using a non-Hyperf framework, copy the `./vendor/dtm/dtm-client/publish/dtm.php` file to the corresponding configuration directory.

```php
use DtmClient\Constants\Protocol;
use DtmClient\Constants\DbType;

return [
// The communication protocol between the client and the DTM Server, supports Protocol::HTTP and Protocol::GRPC
'protocol' => Protocol::HTTP,
// DTM Server address
'server' => '127.0.0.1',
// DTM Server port
'port' => [
'http' => 36789,
'grpc' => 36790,
],
// Sub-transaction barrier
'barrier' => [
// Subtransaction barrier configuration in DB mode
'db' => [
'type' => DbType::MySQL
],
// Subtransaction barrier configuration in Redis mode
'redis' => [
// Timeout for subtransaction barrier records
'expire_seconds' => 7 * 86400,
],
// Classes that apply sub-transaction barriers in non-Hyperf frameworks or without annotation usage
'apply' => [],
],
// Options of Guzzle client under HTTP protocol
'guzzle' => [
'options' => [],
],
];
```

## Configure middleware

Before using it, you need to configure the `DtmClient\Middleware\DtmMiddleware` middleware as the server's global middleware. This middleware supports the PSR-15 specification and is applicable to all frameworks that support this specification.
For middleware configuration in Hyperf, please refer to [Hyperf Documentation - Middleware](https://www.hyperf.wiki/2.2/#/zh-cn/middleware/middleware) chapter.
[Installation Guide](/Docs/install.md)

# Usage

Expand Down

0 comments on commit b58999f

Please sign in to comment.