Code Monkey home page Code Monkey logo

evently's Introduction

evently

Goal

We want to develop a framework for microservices.

Our goal is to seamlessly integrate various communication protocols and provide a unified and easy to read interface for the developers

Types of communication protocols we want to support:

  • HTTP (REST, SOAP)
  • AMQP
  • WebSockets
  • gRPC (?)

Users Interface

We want to use similar approach to the one used in chalice, fastapi, flask and other lightweight frameworks

http = HTTPRouter()
rest = RestRouter()
amqp = AMQPRouter('amqp://localhost:5672')
ws = WebSocketRouter()


@http.get("/hello")
async def hello_http():
    return "<html><body><h1>Hello World</h1></body></html>"


@rest.get('/hello') # get, post, put, delete, patch, etc.
async def hello(hello_request: HelloRequest):
    return {"message": f"Hello {hello_request.name}"}


@amqp.consume(queue='hello')
async def hello_amqp(message: dict, consumer) -> None:
    print(message)
    

@amqp.consume(queue='first-queue')
@amqp.produce(name="instant_producer", queue='second-queue', instantly=True)
@amqp.produce(name="once_finished_producer", queue='second-queue', once_finished=True)
async def msg_handler(message: dict, consumer, instant_producer, once_finished_producer) -> None:
    await once_finished_producer.send({"processed": message}) # message is sent once the handler is finished
    await instant_producer.send({"received": message}) # message is sent instantly
    print(message)
    ... # do some processing


@ws.get("/hello")
async def hello_ws(websocket):
    await websocket.accept()
    while True:
        data = await websocket.receive_json()
        await websocket.send_json(data)


@ws.get("/hello")
@amqp.consume(queue='hello')
@amqp.produce(queue='received')
async def hello_ws_amqp(websocket, consumer, producer):
    await websocket.accept()
    producer.send({"message": websocket.receive_text()})
    while True:
        yield await consumer.receive() # yield is used to send data to the client over websocket
    

@http.get("/hello")
@amqp.produce(name="producer", queue='hello')
async def hello_http_amqp(query: dict, producer):
    yield "<html><body><h1>Hello World</h1></body></html>" # yield is used to send data to the client over http
    producer.send({"message": "Hello World", "query": query})


@rest.get('/hello')
@amqp.produce(queue='hello')
async def hello_rest_amqp(body: HelloRequest, producer):
    yield {"message": f"Hello {body.name}"} # yield is used to send data to the client over http
    producer.send({"message": f"Hello {body.name}"})


app = App()


app.add_router(http)
app.add_router(rest)
app.add_router(ws)
app.add_router(amqp)

evently's People

Contributors

macieyng avatar

Watchers

 avatar

evently's Issues

EXP 3

Cel: zbadać czy można użyć FastAPI life cycle hooks do odpalenia listenerów zarejestrowanych kolejek

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.