## 客户端 创建客户端 ``` $dialer = new \Mix\JsonRpc\Client\Dialer(); $conn = $dialer->dial('127.0.0.1', 9234); ``` 常规调用: ``` $request = (new \Mix\JsonRpc\Factory\RequestFactory)->createRequest('Calculator.Sum', [1, 3], 100001) $response = $conn->call($request); var_dump($response); ``` 批量调用: ``` $requests[] = (new \Mix\JsonRpc\Factory\RequestFactory)->createRequest('Calculator.Sum', [1, 3], 100001) $requests[] = (new \Mix\JsonRpc\Factory\RequestFactory)->createRequest('Calculator.Sum', [2, 3], 100002) $responses = $conn->callMultiple(...$requests); // $responses 不保证顺序,需使用 id 遍历结果 var_dump($responses); ``` - 微服务调用 创建带注册中心的客户端 ``` $dialer = new \Mix\JsonRpc\Client\Dialer([ 'registry' => new \Mix\Etcd\Registry([ 'host' => '127.0.0.1', 'port' => 2379, 'ttl' => 10, ]), ]); $conn = $dialer->dialFromService('php.micro.srv.calculator'); ``` 常规调用: ``` $request = (new \Mix\JsonRpc\Factory\RequestFactory)->createRequest('Calculator.Sum', [1, 3], 100001) $response = $conn->call($request); var_dump($response); ```