aiviaio/nats
Composer 安装命令:
composer require aiviaio/nats
包简介
A nats.io client in PHP
README 文档
README
Travis
| Master | Develop |
|---|---|
Coverage
| Master | Develop |
|---|---|
Introduction
A PHP client for the NATS messaging system.
Requirements
- php 5.6+
- gnatsd
Usage
Installation
Let's start by downloading composer into our project dir:
curl -O http://getcomposer.org/composer.phar
chmod +x composer.phar
Now let's tell composer about our project's dependancies, in this case, PHPNats. The way we do this is by creating a composer.json file, and placing it in the root folder of our project, right next to composer.phar
{
"require": {
"aiviaio/nats": "latest"
}
}
Let's let Composer work its magic:
php composer.phar install
Composer will download all the dependencies defined in composer.json, and prepare all the files needed to autoload them.
Basic Usage
$client = new \Nats\Connection(); $client->connect(); // Publish Subscribe // Simple Subscriber. $client->subscribe( 'foo', function ($message) { printf("Data: %s\r\n", $message->getBody()); } ); // Simple Publisher. $client->publish('foo', 'Marty McFly'); // Wait for 1 message. $client->wait(1); // Request Response // Responding to requests. $sid = $client->subscribe( 'sayhello', function ($message) { $message->reply('Reply: Hello, '.$message->getBody().' !!!'); } ); // Request. $client->request( 'sayhello', 'Marty McFly', function ($message) { echo $message->getBody(); } );
Encoded Connections
$encoder = new \Nats\Encoders\JSONEncoder(); $options = new \Nats\ConnectionOptions(); $client = new \Nats\EncodedConnection($options, $encoder); $client->connect(); // Publish Subscribe // Simple Subscriber. $client->subscribe( 'foo', function ($payload) { printf("Data: %s\r\n", $payload->getBody()[1]); } ); // Simple Publisher. $client->publish( 'foo', [ 'Marty', 'McFly', ] ); // Wait for 1 message. $client->wait(1); // Request Response // Responding to requests. $sid = $client->subscribe( 'sayhello', function ($message) { $message->reply('Reply: Hello, '.$message->getBody()[1].' !!!'); } ); // Request. $client->request( 'sayhello', [ 'Marty', 'McFly', ], function ($message) { echo $message->getBody(); } );
Developer's Information
Releases
Tests
Tests are in the tests folder.
To run them, you need PHPUnit and execute make test-tdd.
We also have a BDD test suite under the spec folder.
To run the suite, you need PHPSpec and execute make test-bdd.
You can also execute the all suites ( TDD + BDD ) with make test.
Code Quality
We are using PHP Code Sniffer to ensure our code follow an high quality standard.
To perform an analysis of the code execute make lint.
There is currently three steps when we lint our code:
- First we lint with php itself
php -l - Then we lint with PSR2 standard
- And finally we lint with a custom ruleset.xml that checks dockblocks and different performance tips.
Creators
Raül Pérez
License
MIT, see LICENSE
aiviaio/nats 适用场景与选型建议
aiviaio/nats 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 02 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 aiviaio/nats 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aiviaio/nats 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 35
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-02-02