Files
chongming-plugins/example/router/add_mqtt.py
T

25 lines
645 B
Python
Raw Normal View History

2026-07-27 14:28:07 +08:00
"""
MQTT 端点处理器 — 通过 MQTT 主题 chongming/example/add 调用
与 GET/POST 的 add 共用同一个 subject (example.add),
通过 _method="MQTT" 区分。
"""
import time
from chongming_worker import rpc_method
from ..models.pydantic import AddMqttRequest
@rpc_method(
subject="example.add",
method="MQTT",
summary="Add two numbers via MQTT",
)
async def add_mqtt(request: AddMqttRequest) -> dict:
"""MQTT 加法 — 通过 MQTT 主题 chongming/example/add 调用,返回 dict"""
return {
"result": request.a + request.b,
"operation": "add_mqtt",
"timestamp": time.time(),
}