diff --git a/.env.example b/.env.example index 40a4645..28060c1 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/README.md b/README.md index 3b78eba..665d68b 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,6 @@ ## 使用方法 ```sh -# 初始化 -./init # composer ./composer install ./composer require xxxx diff --git a/config/jsonrpc.php b/config/jsonrpc.php index b9e1fc4..cbacbe4 100644 --- a/config/jsonrpc.php +++ b/config/jsonrpc.php @@ -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' => [ // /// ... diff --git a/jsonrpc/Client.php b/jsonrpc/Client.php index 76a1f5c..474713a 100644 --- a/jsonrpc/Client.php +++ b/jsonrpc/Client.php @@ -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); - - $uid = 567; - $user_client = RpcClient::instance('User'); - // ==同步调用== - $ret_sync = $user_client->getInfoByUid($uid); - - // ==异步调用== - // 异步发送数据 - $user_client->asend_getInfoByUid($uid); - $user_client->asend_getEmail($uid); +// ======== 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); - 这里是其它的业务代码 - .............................................. - - // 异步接收数据 - $ret_async1 = $user_client->arecv_getEmail($uid); - $ret_async2 = $user_client->arecv_getInfoByUid($uid); - * - * @author walkor - */ 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'); @@ -267,4 +235,4 @@ class Client fclose($this->connection); $this->connection = null; } -} \ No newline at end of file +}