bitninja/ninjarpc
Composer 安装命令:
composer require bitninja/ninjarpc
包简介
Microservice RPC through message queues.
README 文档
README
The easy to use queue based RPC library. You can use any queueing system and any ancoding to connect your server and client. With ninjaRPC you can setup your PHP based microservice stack.
Installation
composer require bitninja/ninjarpc ~2.1
Example Server
use BitNinja\NinjaRpc\Server;
use BitNinja\NinjaRpc\Encoders\JsonEncoder;
use BitNinja\NinjaRpc\QueueManagers\RabbitMQ;
// Target service
$ping = function($param1){
echo 'ping was called!';
};
// Set up a queue manager
$queueManager = new RabbitMQ();
// Set up an encoder
$encoder = new JsonEncoder();
// Set up a router
$router = new SimpleRouter([
'ping' => $ping
]);
// Create the server
$server = new Server('TestServer', $queueManager, $encoder, $router);
// Serve requests forever
while (1) {
$server->listen();
}
Example Client
use BitNinja\NinjaRpc\Client;
use BitNinja\NinjaRpc\Encoders\JsonEncoder;
use BitNinja\NinjaRpc\QueueManagers\RabbitMQ;
// Set up a queue manager
$queueManager = new RabbitMQ()
// Set up an encoder
$encoder = new JsonEncoder();
// Create the client
$client = new Client($queueManager, $encoder);
// Invoke an rpc call
$call = $client->asyncCall('TestServer', 'ping', ['param1' => 'pong']);
// Wait for the response
$call->wait();
// Debug dump the results
$call->dumpResult();
Motivation
Recently microservices has more and more popularity, and one of the best way for your services to communicate with each other is throug message queues. There are a lot fo different queueing systems. The most famous general puprose queueing ssgem is RabbitMQ, but you can use redis, ActiveMQ, Kafka, etc.
NinjaRPC manages all the nasty details behind the scenes of an RPC call using a message queue. Doing an RPC call is not simply sending a message. You have to deal with the response too, take care of declaring the queues, handle timeouts, etc. This is where NinjaRPC helps you.
You can use the built in queue implementations or create your own implementation. (please send me a pull request if you implement new queuing systems)
Also you have the freedom to choose a coding. I have implemented some basic encoders like the PHP built in serialize and json, but you are free to implement any other encoders to us.
API Reference
Tests
Unit tests
You can run the unit tests using phpunit. Simply run it at the root of the git source tree, and it will run all the unit tests and generate shiny reports.
Integration tests
You can run a basic integration test. Make sure to set up a rabbitmq server with default configurations, or start a docker for it first.
$ docker run -d --hostname my-rabbit --name some-rabbit rabbitmq:3
Then you can start the integration tests. Start with the server.
$ cd example
$ php ./server.php
Then in a new console start the client too.
$ cd example
$ php ./client.php
Contributors
Any contribution is very welcome! If you implement new queue drivers or encoders, please send a pull request.
License
MIT license.
bitninja/ninjarpc 适用场景与选型建议
bitninja/ninjarpc 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24.86k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 11 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「redis」 「rpc」 「json」 「rabbitmq」 「protobuf」 「protocol-buffers」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bitninja/ninjarpc 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bitninja/ninjarpc 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bitninja/ninjarpc 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
The CodeIgniter Redis package
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
贝嘟分布式缓存扩展
swagger-php - Generate interactive documentation for your RESTful API using phpdoc annotations
统计信息
- 总下载量: 24.86k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-11-17