scaytrase/json-rpc-client
Composer 安装命令:
composer require scaytrase/json-rpc-client
包简介
JSON-RPC 2.0 Client implementation
README 文档
README
JSON-RPC 2.0 Client implementation
Extension of scaytrase/rpc-common
- JSON RPC Interfaces
- JSON RPC client
- Async with Guzzle
- Automatic batch with multiple requests or
LazyClientDecorator
Usage
- Configure a Guzzle client.
- Instantiate the client:
use ScayTrase\Api\JsonRpc\JsonRpcClient; $client = new JsonRpcClient($guzzleClient, 'http://endpoint/url/');
- Optionally pass the ID generator as third argument and the PSR-3 logger as the fourth argument
Simple UUID generator and PSR-3 NullLogger are used by default. ID is generated for RpcRequestInterface instances.
If request is instance of JsonRpcRequestInterface and does not contain an ID assigned, the request is traited as
notification request and will not receive the response from server.
- Create a
RpcRequestInterfaceinstance
With JsonRpcRequest class:
$request = new \ScayTrase\Api\JsonRpc\JsonRpcRequest('my/method', ['param1' => 'val1'], 'request_id'); $notification = new \ScayTrase\Api\JsonRpc\JsonRpcRequest('my/method', ['param1' => 'val1']);
With JsonRpcNotification class:
$notification = new \ScayTrase\Api\JsonRpc\JsonRpcNotification('my/method', ['param1' => 'val1']);
With custom RpcRequestInterface implementation:
final class MyRpcRequest implements \ScayTrase\Api\Rpc\RpcRequestInterface { public function getMethod() { return 'my/method'; } public function getParameters() { return ['param1' => 'val1']; } } $request = new MyRpcRequest;
- Call the client
/** @var \ScayTrase\Api\Rpc\RpcClientInterface $client */ /** @var \ScayTrase\Api\Rpc\RpcRequestInterface $request */ $collection = $client->invoke($request); $collection = $client->invoke([$request]);
The collection object contains the mapping between the requests and the responses
/** @var \ScayTrase\Api\Rpc\RpcRequestInterface $request */ /** @var \ScayTrase\Api\Rpc\ResponseCollectionInterface $collection */ $response = $collection->getResponse($request);
Decorating
Refer scaytrase/rpc-common base library for some
useful decorators:
CacheableRpcClientLazyRpcClientLoggableRpcClientProfiledClientTraceableClient
scaytrase/json-rpc-client 适用场景与选型建议
scaytrase/json-rpc-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 156.85k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2016 年 01 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 scaytrase/json-rpc-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 scaytrase/json-rpc-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 156.85k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 10
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-01-22