2017 © Pedro Peláez
 

library rpc-client

微服务rpc 调用client

image

connor/rpc-client

微服务rpc 调用client

  • Monday, May 28, 2018
  • by cclehui
  • Repository
  • 1 Watchers
  • 2 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

适用场景

在微服务和服务化的场景下,项目之间存在很多的远程调用场景,在一次请求中存在多次的远程rpc调用, 这种远程调用有的是基于tcp的,有的是基于http的, 为了提升调用性能,我们必须支持异步并发调用, 同时,我们还必须跟踪每次调用的调用链。RpcClient正好解决用来解决这两个问题。, (*1)

安装

直接通过composer安装, (*2)

功能和使用说明

基于http协议的rpc调用

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)

StreamSocketHandler

见demo中的config配置, 可以配置该handler, (*5)

SocketHandler

见demo中的config配置, 可以配置该handler, (*6)

The Versions

28/05 2018

dev-master

9999999-dev

微服务rpc 调用client

  Sources   Download

MIT

The Requires

 

client rpc 微服务 调用端

03/04 2018

1.0.1

1.0.1.0

微服务rpc 调用client

  Sources   Download

MIT

The Requires

 

client rpc 微服务 调用端

03/04 2018

1.0.0

1.0.0.0

微服务rpc 调用client

  Sources   Download

MIT

The Requires

 

client rpc 微服务 调用端