Skip to content

meirdev/mqtt-rpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>)

About

Implementation of RPC over MQTT.

Topics

Resources

License

Stars

Watchers

Forks