Code Monkey home page Code Monkey logo

ansq's Introduction

ansq - Async NSQ

PyPI version Tests Coverage PyPI - Python Version

Written with native Asyncio NSQ package

Installation

python -m pip install ansq

Overview

  • Reader — high-level class for building consumers with nsqlookupd support
  • Writer — high-level producer class supporting async publishing of messages to nsqd over the TCP protocol
  • NSQConnection — low-level class representing a TCP connection to nsqd:
    • full TCP wrapper
    • one connection for sub and pub
    • self-healing: when the connection is lost, reconnects, sends identify and auth commands, subscribes to previous topic/channel

Features

  • SUB
  • PUB
  • Discovery
  • Backoff
  • TLS
  • Deflate
  • Snappy
  • Sampling
  • AUTH

Usage

Consumer

A simple consumer reads messages from "example_topic" and prints them to stdout.

import asyncio

import ansq


async def main():
    reader = await ansq.create_reader(
        topic="example_topic",
        channel="example_channel",
    )

    async for message in reader.messages():
        print(f"Message: {message.body}")
        await message.fin()

    await reader.close()


if __name__ == "__main__":
    asyncio.run(main())

Producer

A simple producer sends a "Hello, world!" message to "example_topic".

import asyncio

import ansq


async def main():
    writer = await ansq.create_writer()
    await writer.pub(
        topic="example_topic",
        message="Hello, world!",
    )
    await writer.close()


if __name__ == "__main__":
    asyncio.run(main())

Contributing

Create and activate a development virtual environment.

python -m venv venv
source venv/bin/activate

Install ansq in editable mode and its testing dependencies.

python -m pip install -e .[testing]

Run tests.

pytest

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.