调整jsonrpc/Client中的注释,config/jsonrpc中的配置方式

This commit is contained in:
wandoubaba517 2024-01-08 15:58:55 +08:00
parent a498fb6267
commit b24b9bbd00
4 changed files with 32 additions and 62 deletions

View File

@ -10,6 +10,10 @@ MAX_PACKAGE_SIZE = 1024*1024*5
# monitor进程
MONITOR_ENABLED = false
# jsonrpc客户端配置
DEFAULT_RPC_SERVER = tcp://127.0.0.1:8022
USER_RPC_SERVER = tcp://127.0.0.1:8022
# jsonrcp服务配置
JSONRPC_ENABLED = true
JSONRPC_SERVER_NAME = jsonrpc

View File

@ -9,8 +9,6 @@
## 使用方法
```sh
# 初始化
./init
# composer
./composer install
./composer require xxxx

View File

@ -6,10 +6,10 @@
return [
'default' => [
'tcp://127.0.0.1:' . env('JSONRPC_SERVER_PORT', 8021), // rpc服务端的地址和端口
env('DEFAULT_RPC_SERVER', 'tcp://127.0.0.1:8021'), // rpc服务端的地址和端口
],
'user' => [
'tcp://127.0.0.1:8022',
env('USER_RPC_SERVER', 'tcp://127.0.0.1:8022'), // rpc服务端的地址和端口
],
// 'server2' => [
// /// ...

View File

@ -17,62 +17,30 @@ namespace jsonrpc;
use Protocols\JsonNL;
/**
* Aaron修改注释
* 需要在config目录下创建jsonrpc.php文件内容如下:
*
return [
'default' => [
'tcp://127.0.0.1:11002', // rpc服务端的地址和端口
],
'server1' => [
/// ...
],
'server2' => [
/// ...
]
];
*
* 客户端的调用方法
// 调用default服务组中Demo类中的hello方法并传入参数$name
$res = RpcClient::service('default', 'Demo')->hello($name);
// 调用server1服务组中User类中的login方法并传入参数$name, $password,
$res = RpcClient::service('server1', 'User')->login($userName, $userPassword);
*/
/**
*
* RpcClient Rpc客户端
*
*
* 示例
* // 服务端列表
$address_array = array(
'tcp://127.0.0.1:2015',
'tcp://127.0.0.1:2015'
);
// 配置服务端列表
RpcClient::config($address_array);
// ======== jsonrpc客户端使用方法 ========
//
// 需要在config目录下创建jsonrpc.php文件内容如下:
//
// return [
// 'default' => [
// 'tcp://127.0.0.1:11002', // rpc服务端的地址和端口
// ],
// 'server1' => [
// /// ...
// ],
// 'server2' => [
// /// ...
// ]
// ];
//
// 客户端的调用方法:
//
// **** 调用default服务组中Demo类中的hello方法并传入参数$name
// $res = RpcClient::service('default', 'Demo')->hello($name);
// **** 调用server1服务组中User类中的login方法并传入参数$name, $password,
// $res = RpcClient::service('server1', 'User')->login($userName, $userPassword);
$uid = 567;
$user_client = RpcClient::instance('User');
// ==同步调用==
$ret_sync = $user_client->getInfoByUid($uid);
// ==异步调用==
// 异步发送数据
$user_client->asend_getInfoByUid($uid);
$user_client->asend_getEmail($uid);
这里是其它的业务代码
..............................................
// 异步接收数据
$ret_async1 = $user_client->arecv_getEmail($uid);
$ret_async2 = $user_client->arecv_getInfoByUid($uid);
*
* @author walkor <worker-man@qq.com>
*/
class Client
{
/**
@ -219,9 +187,9 @@ class Client
{
$this->openConnection();
$bin_data = JsonNL::encode(array(
'class' => $this->serviceName,
'method' => $method,
'param_array' => $arguments,
'class' => $this->serviceName,
'method' => $method,
'param_array' => $arguments,
));
if (fwrite($this->connection, $bin_data) !== strlen($bin_data)) {
throw new \Exception('Can not send data');