Giter VIP home page Giter VIP logo

aionsq's Introduction

aionsq (Not Maintained )

asyncio (PEP 3156) nsq (message queue) client.

Usage examples

Simple low-level interface:

import asyncio
from aionsq.connection import create_connection


def main():

    loop = asyncio.get_event_loop()
    @asyncio.coroutine
    def go():
        # create tcp connection
        nsq = yield from create_connection(port=4150, loop=loop)
        # publish b'test_msg' to the topic: b'foo'
        ok = yield from nsq.execute(b'PUB', b'foo', data=b'test_msg')
        # subscribe to the b'foo' topic and b'bar' channel
        yield from nsq.execute(b'SUB', b'foo', b'bar')
        # tell nsqd that we are reade receive 1 message
        yield from nsq.execute(b'RDY', b'1')
        # wait for message
        msg = yield from nsq._msq_queue.get()
        print(msg)
        # acknowledge message
        yield from nsq.execute(b'FIN', b'1')

    loop.run_until_complete(go())

if __name__ == '__main__':
    main()

High-level interface for one nsq connection:

import asyncio
from aionsq.nsq import create_nsq


def main():

    loop = asyncio.get_event_loop()
    @asyncio.coroutine
    def go():
        nsq = yield from create_nsq(host='127.0.0.1', port=4150, loop=loop)
        yield from nsq.pub(b'foo', b'msg foo')
        yield from nsq.sub(b'foo', b'bar')
        yield from nsq.rdy(1)
        msg = yield from nsq.wait_messages()
        print(msg)
        yield from msg.fin()
    loop.run_until_complete(go())


if __name__ == '__main__':
    main()

Requirements

License

The aionsq is offered under MIT license.

aionsq's People

Contributors

jettify avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

aionsq's Issues

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.