-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9540bff
commit b58999f
Showing
4 changed files
with
164 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters