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

25 lines
645 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
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(),
}