https://github.com/hyperf/rpc-multiplex
[READ ONLY] Rpc for multiplexing connection
https://github.com/hyperf/rpc-multiplex
Last synced: 6 months ago
JSON representation
[READ ONLY] Rpc for multiplexing connection
- Host: GitHub
- URL: https://github.com/hyperf/rpc-multiplex
- Owner: hyperf
- License: mit
- Created: 2021-06-29T06:00:55.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-26T02:43:12.000Z (almost 2 years ago)
- Last Synced: 2024-04-26T03:35:20.735Z (almost 2 years ago)
- Language: PHP
- Size: 51.8 KB
- Stars: 8
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rpc for multiplexing connection
[](https://github.com/hyperf/rpc-multiplex-incubator/actions/workflows/test.yml)
## 安装
```
composer require hyperf/rpc-multiplex
```
## Server 配置
修改 `config/autoload/server.php` 配置文件
> 删除不相干配置
```php
[
[
'name' => 'rpc',
'type' => Server::SERVER_BASE,
'host' => '0.0.0.0',
'port' => 9502,
'sock_type' => SWOOLE_SOCK_TCP,
'callbacks' => [
Event::ON_RECEIVE => [Hyperf\RpcMultiplex\TcpServer::class, 'onReceive'],
],
'settings' => [
'open_length_check' => true,
'package_length_type' => 'N',
'package_length_offset' => 0,
'package_body_offset' => 4,
'package_max_length' => 1024 * 1024 * 2,
],
],
],
];
```
创建 `RpcService`
```php
[
[
'name' => 'CalculatorService',
'service' => App\JsonRpc\CalculatorServiceInterface::class,
'id' => App\JsonRpc\CalculatorServiceInterface::class,
'protocol' => Hyperf\RpcMultiplex\Constant::PROTOCOL_DEFAULT,
'load_balancer' => 'random',
'nodes' => [
['host' => '127.0.0.1', 'port' => 9502],
],
'options' => [
'connect_timeout' => 5.0,
'recv_timeout' => 5.0,
'settings' => [
// 包体最大值,若小于 Server 返回的数据大小,则会抛出异常,故尽量控制包体大小
'package_max_length' => 1024 * 1024 * 2,
],
// 重试次数,默认值为 2
'retry_count' => 2,
// 重试间隔,毫秒
'retry_interval' => 100,
// 多路复用客户端数量
'client_count' => 4,
// 心跳间隔 非 numeric 表示不开启心跳
'heartbeat' => 30,
],
],
],
];
```