scottaubrey/simplensqclient
最新稳定版本:0.2.0-alpha
Composer 安装命令:
composer require scottaubrey/simplensqclient
包简介
Simple library for NSQ realtime distributed messaging platform nsqd protocol
关键字:
README 文档
README
Overview
This is a PHP library for NSQ realtime distributed messaging platform nsqd protocol written in PHP. simplensqclient has no other dependancies outside of the core PHP distribution, but does require PHP > 5.5.
simplensqclient implements most, but not all of NSQ's platform functionality.
"Simple" refers to the subscription handling. The library does not follow the recommendations of the NSQ project for client design, more specifically it does not use any kind of threading, or asynchronous IO event loop for socket handling and message processing. The NSQPHP library (https://github.com/davegardnerisme/nsqphp) utilises the react PHP event loop and library ecosystem to implement this type of client.
Instead simplensqclient uses an asynchronous loop for the connections for a cluster, waiting for one to be ready. Each message is then processed one by one before returning to the loop waiting for more ready connections. The API presented is a Generator returning each messages one by one, a much simpler API design than having your processing in an event loop.
This does present one major limitation: If you do a lot of intensive processing with each message, you are going to get problems with throughput and message timeouts. However, for short, event-like message processing though, it should work fine, and a larger throughput can be acheived by running more subscription clients.
This library is currently alpha status. simplensqclient has no real world production use (AFAIK).
Supported NSQ protocol features
| Feature | Supported | notes |
|---|---|---|
| PUB | Yes | |
| SUB | Yes | only 1 message inflight from each nsqd instance |
| TLS | Yes | |
| Deflate | Yes | requires PHP compiled with zlib and doesn't work in any known released PHP without patching the zlib stream wrapper, see PHP BUG #48725 |
| AUTH | Yes | |
| Reconnect Backoff | Yes | |
| Discovery | Yes | |
| Message Backoff | No | Probably not needed because the client never ramps up to backoff currently. |
| Snappy | No | no stream wrapper support in PHP |
| Sampling | No |
Getting started
Add scottaubrey/simplensqclient to composer using the composer require command
composer.phar require "scottaubrey/simplensqclient"
Then you can publish a message to an nsqd:
//create an NSQ instance with default hostname and port
$nsq = new NsqConnection;
//publish a simple string message
$nsq->publish("TestTopic", "My Message");
and subscribe to a single nsqd (one message at a time):
//create an NSQ instance with default hostname and port
$nsq = new NsqConnection;
//publish a simple string message
foreach ($nsq->subscribe("TestTopic", "MyTestChannel") as $messageId => $message) {
$nsq->finish($messageId);
}
There are other examples in the examples directory
Roadmap
These are the tasks to be done before 1.0:
- Connection options - particularly allow configuring message timeout and heartbeat interval.
- Tidy up API, Doc blocks
- Publish strategies - currently only round-robin publishing is supported.
Things to try at some point:
- Investigate support for PCNTL and/or pthreads (https://github.com/krakjoe/pthreads) - with one thread for reading the connections, while processing messages in another process/thread.
- Deduplication of messages - NSQPHP (https://github.com/davegardnerisme/nsqphp) provides a deduplication layer on top of the base library based on a bloom filter. This library, for the moment, assumes the comsumer is aware of the At-Least-Once nature of the NSQ platform.
License
This library is license under the open source MIT license, the text included in the root folder.
scottaubrey/simplensqclient 适用场景与选型建议
scottaubrey/simplensqclient 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 130 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 03 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「nsq」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 scottaubrey/simplensqclient 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 scottaubrey/simplensqclient 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 scottaubrey/simplensqclient 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 130
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-03-12