eliep/avro-rpc-php-generator
Composer 安装命令:
composer require eliep/avro-rpc-php-generator
包简介
This library generates an Avro RPC client based on eliep/avro-rpc-php
关键字:
README 文档
README
See Avro for a full documentation on Avro and its usage in PHP.
This library use avro-rpc-php as an implementation of the Avro RPC protocol in php.
Installation
composer require eliep/avro-rpc-php-generator
Protocol class Generation
The script is located in your vendor/bin folder:
php vendor/bin/generate.php --help
Required arguments:
- --input (-i) dir : The folder containing your Avro protocol
- --output (-o) dir : The folder where the protocol classes will be written
Optional argument:
- --prefix (-p) namespace: The namespace prefix of the output directory
- --stringType (-s) : If the requestor will be used with a java implementation using String instead of CharSequence
- --apcu (-a) : use APCu to cache the parsed protocol.
Namespacing
The generate script will respect the namespace defined in your avro protocol. For example, if you have define "my.avro" as your protocol namespace, the script:
- create the folder
My\Avroin the directory specified by the -o option. - use
My\Avrofor the generated php class.
Note: If the directory specified by the -o option has a namespace, you can use the option -p to specify it so that the namespace of the generated php class will use it.
The name of the generate class will be protocol name with the Requestor suffix
(if your protocol's name is Protocol, the class name will be ProtocolRequestor);
Protocol class Usage
For example, if your protocol is:
{
"namespace": "my.avro",
"protocol": "Protocol",
"types": [
{"type": "record", "name": "SimpleRequest",
"fields": [{"name": "subject", "type": "string"}]
},
{"type": "record", "name": "SimpleResponse",
"fields": [{"name": "something", "type": "string"}]
}
],
"messages": {
"requestSomething": {
"request": [{"name": "message", "type": "SimpleRequest"}],
"response": "SimpleResponse"
}
}
}
you can connect to an Avro RPC Server with
use My\Avro\ProtocolRequestor $serverHost = '127.0.0.1'; $serverPort = 1412; try { $requestor = new ProtocolRequestor($serverHost, $serverPort); } catch (\Exception $e) { // unable to reach the server. }
The ProtocolRequestor set a temporary error handler to detect if the socket connection
worked. If not, the constructor throw a php Exception.
The ProtocolRequestor class contains one function for each message in your protocol.
These functions accept as many argument as defined by the corresponding message.
You can call:
$response = $requestor->requestSomething(array("subject" => "ping"));
Example
An example is available in example/ folder.
- Start a server
php bin/generate.php sample_rpc_server.php
- Use the sample client
php bin/generate.php sample_rpc_client.php
- Regenerate the sample client
php bin/generate.php --input example/avro/ --output example/ --prefix Example --stringType
eliep/avro-rpc-php-generator 适用场景与选型建议
eliep/avro-rpc-php-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 266 次下载、GitHub Stars 达 6, 最近一次更新时间为 2016 年 08 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rpc」 「serialization」 「avro」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 eliep/avro-rpc-php-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 eliep/avro-rpc-php-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 eliep/avro-rpc-php-generator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Fork of jms/serializer 1.14.1 with support for modern PHP versions.
Microservice RPC through message queues.
PHP avro schema generator for subschema
A library to serialize and deserialize Avro records making use of the confluent schema registry
De/normalize business objects without tightly coupling them to your normalization format
Runn Me! Serialization Library
统计信息
- 总下载量: 266
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2016-08-20