2022-11-04 15:37:04 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
/**
|
|
|
|
|
* This file is part of Hyperf.
|
|
|
|
|
*
|
|
|
|
|
* @link https://www.hyperf.io
|
|
|
|
|
* @document https://hyperf.wiki
|
|
|
|
|
* @contact group@hyperf.io
|
|
|
|
|
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
|
|
|
|
*/
|
|
|
|
|
return [
|
|
|
|
|
'enable' => [
|
|
|
|
|
'discovery' => true,
|
|
|
|
|
'register' => true,
|
|
|
|
|
],
|
2022-11-07 16:29:37 +08:00
|
|
|
|
'consumers' => value(function () {
|
|
|
|
|
$consumers = [];
|
|
|
|
|
// 这里示例自动创建代理消费者类的配置形式,顾存在 name 和 service 两个配置项,这里的做法不是唯一的,仅说明可以通过 PHP 代码来生成配置
|
|
|
|
|
$services = [
|
2022-11-16 15:41:43 +08:00
|
|
|
|
'UserExternalService' => '',
|
2022-11-15 16:33:33 +08:00
|
|
|
|
'PunchCardSystemExternalService' => ''
|
2022-11-07 16:29:37 +08:00
|
|
|
|
];
|
|
|
|
|
foreach ($services as $name => $interface) {
|
|
|
|
|
$consumers[] = [
|
|
|
|
|
'name' => $name,
|
|
|
|
|
'service' => $interface,
|
|
|
|
|
'protocol' => 'jsonrpc-http',
|
|
|
|
|
'registry' => [
|
|
|
|
|
'protocol' => 'consul',
|
|
|
|
|
'address' => env('CONSUL_URL', '127.0.0.1:8500'),
|
|
|
|
|
],
|
|
|
|
|
// 配置项,会影响到 Packer 和 Transporter
|
|
|
|
|
'options' => [
|
|
|
|
|
'connect_timeout' => 5.0,
|
|
|
|
|
'recv_timeout' => 5.0,
|
|
|
|
|
'settings' => [
|
|
|
|
|
// 根据协议不同,区分配置
|
|
|
|
|
'open_eof_split' => true,
|
|
|
|
|
'package_eof' => "\r\n",
|
|
|
|
|
// 'open_length_check' => true,
|
|
|
|
|
// 'package_length_type' => 'N',
|
|
|
|
|
// 'package_length_offset' => 0,
|
|
|
|
|
// 'package_body_offset' => 4,
|
|
|
|
|
],
|
|
|
|
|
// 重试次数,默认值为 2,收包超时不进行重试。暂只支持 JsonRpcPoolTransporter
|
|
|
|
|
'retry_count' => 2,
|
|
|
|
|
// 重试间隔,毫秒
|
|
|
|
|
'retry_interval' => 100,
|
|
|
|
|
// 使用多路复用 RPC 时的心跳间隔,null 为不触发心跳
|
|
|
|
|
'heartbeat' => 30,
|
|
|
|
|
// 当使用 JsonRpcPoolTransporter 时会用到以下配置
|
|
|
|
|
'pool' => [
|
|
|
|
|
'min_connections' => 1,
|
|
|
|
|
'max_connections' => 32,
|
|
|
|
|
'connect_timeout' => 10.0,
|
|
|
|
|
'wait_timeout' => 3.0,
|
|
|
|
|
'heartbeat' => -1,
|
|
|
|
|
'max_idle_time' => 60.0,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
return $consumers;
|
|
|
|
|
}),
|
2022-11-04 15:37:04 +08:00
|
|
|
|
'providers' => [],
|
|
|
|
|
'drivers' => [
|
|
|
|
|
'consul' => [
|
|
|
|
|
'uri' => env('CONSUL_URL', '127.0.0.1:8500'),
|
|
|
|
|
'token' => '',
|
|
|
|
|
'check' => [
|
|
|
|
|
'deregister_critical_service_after' => '90m',
|
|
|
|
|
'interval' => '1s',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|