Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rpc proxy client #336

Merged
merged 12 commits into from
Aug 7, 2019
Merged

Conversation

wenbinye
Copy link
Contributor

@wenbinye wenbinye commented Aug 6, 2019

使用 ast 生成代理类调用 rpc 服务

fix #306

@wenbinye
Copy link
Contributor Author

wenbinye commented Aug 6, 2019

\Hyperf\RpcClient\Pool\RpcClientPool 这个看上去没有用,transporter 是每次创建新对象,没有使用对象池,是不是要删除?

@limingxinleo
Copy link
Member

最后就只剩下一个问题了。。那就是生成的 代理 Client,没有办法被 AOP 切入。。

@wenbinye
Copy link
Contributor Author

wenbinye commented Aug 6, 2019

刚刚把 ServiceClient 创建使用 make 函数创建,如果需要可以替换对应的实现或者加 AOP

@limingxinleo limingxinleo self-requested a review August 7, 2019 03:53
Copy link
Member

@huangzhhui huangzhhui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@limingxinleo 除了最后的那个 conversation 就是 if 的合并,我没有其它问题了,你看看
@wenbinye 关于 RPC 的代理客户端,还需要补充一下文档的内容,文档可以在另一个 PR,然后关联一下

Copy link
Member

@limingxinleo limingxinleo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最后一个 commit,看一下,应该是没问题的。。

@huangzhhui @wenbinye

@limingxinleo
Copy link
Member

    protected function __request(string $method, array $params, ?string $id = null)
    {
        if ($this->idGenerator instanceof IdGeneratorInterface && ! $id) {
            $id = $this->idGenerator->generate();
        }
        $response = $this->client->send($this->__generateData($method, $params, $id));
        if (! is_array($response)) {
            throw new RequestException('Invalid response.');
        }

        if (isset($response['result'])) {
            $type = $this->methodDefinitionCollector->getReturnType($this->serviceName, $method);
            return $this->normalizer->denormalize($response['result'], $type->getName());
        }

        if ($code = $response['error']['code'] ?? null) {
            $error = $response['error'];
            // Denormalize exception.
            $class = Arr::get($error, 'data.class');
            $attributes = Arr::get($error, 'data.attributes', []);
            if (isset($class) && class_exists($class) && $e = $this->normalizer->denormalize($attributes, $class)) {
                if ($e instanceof \Exception) {
                    throw $e;
                }
            }

            // Throw RequestException when denormalize exception failed.
            throw new RequestException($error['message'] ?? '', $error['code']);
        }

        throw new RequestException('Invalid response.');
    }

@huangzhhui @wenbinye 最后再 review 一下看看。。

@limingxinleo limingxinleo merged commit 6d4a9e2 into hyperf:master Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] 支持自定义类型 jsonrpc 调用
3 participants