Git Product home page Git Product logo

nsqworker's Introduction

Overview

nsqworker is a skeletal code of one way to implement nsq consumer(worker) in Python base on pynsq.

Installation

pip install nsqworker

Demo

Go to nsqworker root folder and run:

python bootstrap.py

Publish a message to topic demo:

curl -d '{"clicks": 10}' 'http://127.0.0.1:4151/put?topic=demo'

then the demo worker will output:

demo: demo/pageview, clicks 10

If run bootstrap.py in command like below:

python bootstrap.py --topic=newtopic --channel=newchannel

It will try to run NewtopicNewchannelWorker from workers/newtopic/newtopic_newchannel_worker.py which subscribes messages of newtopic/newchannel, of course, you need implement this worker.

Conventions

  1. Keep all of nsq workers of a topic in a sub-folder named the same as the topic name, eg. nsqworker/workers/demo/
  2. Create a channel's worker in a file named {topic}/{topic}_{channel}_worker.py, eg. workers/demo/demo_pageview_worker.py
  3. Implement the channel worker class, it should inherit from nsqworker.Worker, eg. DemoPageviewWorker(Worker)
  4. Add a functional endswith "_handler"(eg. demo_handler) in the worker to handle messages, this functional will be treated as a message_handler in pynsq automatically, you can add more than one handlers.

It is easy to implement a customize consumer follow this conventions.

Customize your bootstrap.py

from nsqworker.bootstrap import run
# Customize workers_module which default value is nsqworker.workers(The root module of demo workers)
# You should set it to yourpackage.workers.
run("yourpackage.workers")

Then it will load and run workers under yourpackage.workers like nsqworker.bootstrap.py

nsqworker's People

Contributors

aaronjheng avatar felinx avatar tevino avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nsqworker's Issues

啥原因跑不了?飞龙

Traceback (most recent call last):
File "bootstrap.py", line 30, in
run("workers")
File "/usr/local/lib/python2.7/dist-packages/nsqworker/bootstrap.py", line 59, in run
if options.debug:
File "/usr/local/lib/python2.7/dist-packages/tornado/options.py", line 125, in getattr
raise AttributeError("Unrecognized option %r" % name)
AttributeError: Unrecognized option 'debug'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.