Skip to content

jettify/aionsq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published