dev-master
9999999-dev微服务rpc 调用client
MIT
The Requires
client rpc 微服务 调用端
1.0.1
1.0.1.0微服务rpc 调用client
MIT
The Requires
client rpc 微服务 调用端
1.0.0
1.0.0.0微服务rpc 调用client
MIT
The Requires
client rpc 微服务 调用端
微服务rpc 调用client
在微服务和服务化的场景下,项目之间存在很多的远程调用场景,在一次请求中存在多次的远程rpc调用, 这种远程调用有的是基于tcp的,有的是基于http的, 为了提升调用性能,我们必须支持异步并发调用, 同时,我们还必须跟踪每次调用的调用链。RpcClient正好解决用来解决这两个问题。, (*1)
直接通过composer安装, (*2)
HttpRpcClientUtil 在guzzle promise的基础上提供了同步和异步的http 远程调用类封装,在log中 收集了调用的信息,可以用于调用链的性能分析, (*3)
//配置不同的handler来处理 $config = [ // 'handler' => new \GuzzleHttp\Handler\StreamHandler(), // 'handler' => new \CClehui\RpcClient\GuzzleHandler\StreamSocketHandler(), 'handler' => new \CClehui\RpcClient\GuzzleHandler\SocketHandler(), ]; //同步调用demo $url = 'http://0.0.0.0/temp/test.php; $params = []; $rpc_client = new \CClehui\RpcClient\HttpRpcClientUtil(); $rpc_client->setGuzzleClientConfig($config); $res = $rpc_client->callRemote($url, $params); //异步调用demo (promise机制) $url = 'http://0.0.0.0/temp/test.php'; $params = []; $promises = []; $rpc_client = new \CClehui\RpcClient\HttpRpcClientUtil();(); $rpc_client->setGuzzleClientConfig($config); for ($i = 1; $i <= 2; $i++) { $promises[$i] = $rpc_client->callRemote($url, $params, 'GET', [], true); } $result_list = \GuzzleHttp\Promise\settle($promises)->wait(); foreach($result_list as $key => $item) { $response = $item['value']; $response = (string)$response->getBody(); echo $response . "\n"; }
更详细的使用demo在 examples\HttpRpcDemo.php中, (*4)
见demo中的config配置, 可以配置该handler, (*5)
见demo中的config配置, 可以配置该handler, (*6)
微服务rpc 调用client
MIT
client rpc 微服务 调用端
微服务rpc 调用client
MIT
client rpc 微服务 调用端
微服务rpc 调用client
MIT
client rpc 微服务 调用端