You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
777 B
Python
33 lines
777 B
Python
import asyncio
|
|
|
|
from loguru import logger
|
|
|
|
from busrtworker import App, ConnectionInfo
|
|
|
|
app = App()
|
|
|
|
api_ci = ConnectionInfo('api', 'localhost:9800', 'busrt.worker.test', static=True, topic='test/#')
|
|
caller_ci = ConnectionInfo('caller', 'localhost:9800', 'busrt.worker.test', static=True)
|
|
api = app.registry(api_ci)
|
|
app.registry(caller_ci)
|
|
|
|
|
|
@api.on_call()
|
|
def add(a, b):
|
|
return a + b
|
|
|
|
|
|
@api.subscribe('test/:name')
|
|
def print_name(name: str):
|
|
logger.info(f'{name} pub message')
|
|
|
|
@app.run_on_startup
|
|
async def test(server):
|
|
async def call():
|
|
await asyncio.sleep(1)
|
|
logger.info(f'call remote add result {(await app.caller.add(api_ci.final_name,a=1, b=2))}')
|
|
await app.caller.send('test/i_am_caller')
|
|
asyncio.create_task(call())
|
|
|
|
app.run()
|