NSQ for Python
==============
[![Build Status](https://travis-ci.org/dlecocq/nsq-py.png)](https://travis-ci.org/dlecocq/nsq-py)
Clients
=======
TCP Clients
-----------
This library will provide bindings for the TCP interface of `nsqd`, compatible
with three frameworks:
1. `threading` / `select` which should be sufficient for most cases, except for
those using a large number of `nsqd` instances
2. `gevent`, which is actually merely a wrapping of the above with
monkey-patched `threading` and `select` and
3. `tornado` for those used to the original official python client.
It also provides the building blocks for exending this client to work with other
frameworks as well.
HTTP Clients
------------
This also provides bindings for the HTTP interfaces of `nsqlookupd` and `nsqd`
for convenience in `nsq.http`.
Primitives
==========
There are a few primitives you should use when building event-mechanism-specific
bindings:
- `connection.Connection` simply wraps a `socket` and knows how to send commands
and read as many responses as are available on the wire
- `response` has the `Response`, `Error` and `Message` classes which all know
how to unpack and pack themselves.
- `util` holds some utility methods for packing data and other miscellany
Usage
=====
Both the `threading` and `gevent` clients keep the same interface. It's just the
internals that differ. In these cases, the `Reader` might be used like so:
```python
# For the threaded version:
from nsq.reader import Reader
# For the gevent version:
from nsq.gevent import Reader
reader = Reader('topic', 'channel', ...)
for message in reader:
print message
message.fin()
```
If you're using `gevent`, you might want to have a pool of `coroutines` running
code to consume messages. That would look something like this:
```python
from gevent.pool import Pool
pool = Pool(50)
def consume_message(message):
print message
message.fin()
pool.map(consume_message, reader)
```
Closing
-------
You really ought to close your reader when you're done with it. Fortunately,
this is quite-easily done with `contextlib`:
```python
from contextlib import closing
with closing(Reader('topic', 'channel', ...)) as reader:
for message in reader:
....
```
Benchmarks
==========
There is a `shovel` task included in `shovel/profile.py` that runs a basic
consumer benchmark against a local `nsqd` isntance. The most recent benchmark on
a 2011 MacBook Pro shows the `select`-based `Reader` consuming about 105k
messages / second. With `gevent` enabled, it does not appear to be statistically
significantly different.
Running Tests
=============
You'll need to install a few dependencies before invoking the tests:
```python
pip install -r requirements.txt
make test
```
This should run the tests and provide coverage information.
Contributing
============
Help is always appreciated. If you add functionality, please:
- include a failing test in one commit
- a fix for the failing test in a subsequent commit
- don't decrease the code coverage
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
最新资源
- MATLAB(GUI)的人脸门禁【ORL人脸库,库外预警,可增删查】.zip
- 智能驾驶ADAS基础知识(一)
- MATLAB(GUI)的手写字符识别[数字,字母,符号].zip
- MATLAB(GUI)的小波变换dwt数字水印[彩色,评价指标,GUI框架].zip
- MATLAB(GUI)的水果识别分类(分类器,Matlab版运行).zip
- MATLAB(GUI)的语音滤波(FIR,多方法,GUI界面).zip
- Matlab Simulink模型代搭 七自由度整车动力学模型 魔术轮胎模型 轮毂电机模型 软件使用:Matlab Simulink 适用场景:整车动力学建模,Carsim与Simulink联合仿真验
- MATLAB(GUI)的运动行为检测(某行为预警).zip
- MATLAB(GUI)购物系统,无人自助购物(自动计费,历史购物清单查询,GUI框架).zip
- MATLAB(GUI)汉字识别(写字板,GUI界面).zip
- MATLAB(GUI)汉字语音识别(语音转汉字,GUI界面).zip
- MATLAB(GUI)火焰识别[创新点:Bp神经网络].zip
- Delphi 12 控件之GExperts-RS12-1.3.25-2024-08-24.exe
- MATLAB(GUI)火焰识别系统(创新点:面积增长率,面积高度).zip
- MATLAB(GUI)基于DWT+SVD结合傅里叶变换的数字图像水印水印系统(嵌入+攻击+提取).zip
- MATLAB(GUI)火焰烟雾检测(视频,有火焰则预警,GUI).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈