RPC、Yar、gRPC

2016-12-03  本文已影响328人  michael_jia

自 11 月后端结构调整正式启动已有月余,效果初现;
PHP Yar(Yet Another RPC Framework)是我们采取的措施之一;
版本 1.3 开发过程中,Yar 服务 5XX 错误频频,问题解决速度远低于期望;
调试(Debug)技术、测试技术、观测手段的匮乏,恐怕是其中最大的原因之一;
源于超人在 PHPUnit 上的 最新尝试,我们试图在这方面上一个台阶:高质量的敏捷交付;

RPC(Remote Procedure Calling) Mechanism

A remote procedure is uniquely identified by the triple: (program number, version number, procedure number) The program number identifies a group of related remote procedures, each of which has a unique procedure number. A program may consist of one or more versions. Each version consists of a collection of procedures which are available to be called remotely. Version numbers enable multiple versions of an RPC protocol to be available simultaneously. Each version contains a a number of procedures that can be called remotely. Each procedure has a procedure number.

Yar 在 GitHub

Yar is a RPC framework which aims to provide a simple and easy way to do communication between PHP applications.
It has the ability to concurrently call multiple remote services.

示例
<?php
class API {
    public function testName($name) {
        error_log("Hello, $name\n", 3, "/logs/yar.log");
        return "Hello, $name";
    }
    public function testAdd($a, $b) {
        $c = $a + $b;
        error_log("$a + $b = $c\n", 3, "/logs/yar.log");
        return "$a + $b = $c";
    }
}
$service = new Yar_Server(new API());
$service->handle();
<?php
    $client = new Yar_Client("http://api.example.com/yarserver.php");
    echo $client->testName("michael");
    echo $client->testAdd(2,3);
如何对 RPC 服务进行单独测试?
关于 gRPC

Google 名下的开源项目;


Works across languages and platforms

https://gist.github.com/dzlab/2e6e79419877dc29d2efc63ae5974fd5
https://danielmiessler.com/blog/log-post-data-nginx/#gs.ZM_5pEY
http://developers.redhat.com/blog/2016/05/23/configuring-nginx-to-log-post-data-on-linux-rhel/
http://stackoverflow.com/questions/4939382/logging-post-data-from-request-body
https://laracasts.com/discuss/channels/general-discussion/laravel-and-rpc
http://restfulapi.nl/#what1
http://www.jsonrpc.org/
https://miniflux.net/documentation/json-rpc-api
http://pages.cs.wisc.edu/~remzi/OSTEP/dist-intro.pdf

上一篇 下一篇

猜你喜欢

热点阅读