Giter Site home page Giter Site logo

interop's Introduction

Interop

A light-weight PubSub application for python asyncio using RabbitMQ that can stand alone or be embedded in other async code.

Usage

Setup:

from interop import Interop

#: Be sure to load your env values

config: typing.Dict[str, typing.Any] = dict()  #: populate accordingly
interop = Interop(
    os.getenv("IMPORT_NAME"),
    os.getenv("RMQ_BROKER_URI", ""),
)

#: later
async def start():
    await interop.init_app(app=config)
    #: ignore next line if embedded in an async application like Starlette
    await interop()

or scaffold standalone application with cli script:

interop init

also, see the examples folder

Configuration Values

#: Import name for your application
#: CLI commands need the directory for your application to work
IMPORT_NAME="my_app"

#: Rabbit MQ
RMQ_HOST="localhost"
RMQ_PASSWORD="guest"
RMQ_PORT="5672"
#: Use amqps for secure connections
RMQ_SCHEME="amqp"
RMQ_USER="guest"

RMQ_URI="${RMQ_SCHEME}://${RMQ_USER}:${RMQ_PASSWORD}@${RMQ_HOST}:${RMQ_PORT}"
RMQ_BROKER_URI="${RMQ_URI}/%2F?connection_attempts=3&heartbeat=3600"

Sample Publisher

import asyncio
import typing

from interop import publish


@publish
async def sample(app: typing.Dict[str, typing.Any]):
    """This function monitors some external state and publishes directly to the
    rabbitmq broker.

    """

    while True:
        #: Add publishing code here

        await asyncio.sleep(2)  #: Use appropriate sleep time

Sample Subscriber

from interop import Packet
from interop import subscribe


@subscribe("<routing-key>", "<exchange-name>")
async def sample(packet: Packet):
    """This function reacts to messages routed to <routing-key> at
    <exchange-name> on the rabbitmq broker.

    """

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.