Skip to content

Latest commit

 

History

History
55 lines (36 loc) · 757 Bytes

README.md

File metadata and controls

55 lines (36 loc) · 757 Bytes

MQTT RPC

Implementation of RPC over MQTT.

Usage

Run the broker:

cd ./broker && ./run.sh

Create a new app instance (app.py):

from mqtt_rpc import mqtt_rpc

app = mqtt_rpc.MqttRpc("mytest", ["tasks"], {"hostname": "localhost"})

Run the worker:

python -m mqtt_rpc --app app.app worker

Write a task (tasks.py):

from app import app

@app.task
def sum(a, b) -> int:
    return a + b

Send a task to the worker:

import asyncio

import tasks

async def main() -> None:
    res = await tasks.sum.apply_sync(args=[1, 3])
    print(await res.get())

asyncio.run(main())

Result:

Response(id='63408401-f95d-437b-9810-4e5a2b3335ae', result=4, status=<Status.SUCCESS: 2>)