modify: 统一插件风格

This commit is contained in:
2026-08-14 16:03:49 +08:00
parent fe95a67e93
commit f2a3a37389
14 changed files with 306 additions and 53 deletions
+9 -5
View File
@@ -3,10 +3,11 @@ MQTT Publisher — 向 chongming Worker 发送 MQTT 请求
用法:
python publisher.py <worker_type> <operation> [json_payload]
示例:
python publisher.py example add '{"a": 3, "b": 5, "_method": "GET"}'
python publisher.py doubao analyze '{"text": "hello", "_method": "POST"}'
示例(信封协议,meta 可选):
python publisher.py example add '{"meta": {"method": "GET"}, "data": {"a": 3, "b": 5}}'
python publisher.py example add '{"a": 3, "b": 5}' # 扁平载荷自动包装(method=GET)
python publisher.py example add '{"meta": {"method": "MQTT"}, "data": {"a": 3, "b": 5}}'
"""
import asyncio
@@ -24,7 +25,7 @@ PREFIX = "chongming"
# 默认参数
DEFAULT_WORKER = "example"
DEFAULT_OP = "add"
DEFAULT_PAYLOAD = {"a": 3, "b": 5, "_method": "GET"}
DEFAULT_PAYLOAD = {"meta": {"method": "GET"}, "data": {"a": 3, "b": 5}}
async def main():
worker_type = sys.argv[1] if len(sys.argv) > 1 else DEFAULT_WORKER
@@ -33,6 +34,9 @@ async def main():
topic = f"{PREFIX}/{worker_type}/{operation}"
payload = json.loads(payload_str)
# 扁平载荷自动包装为信封(method 默认 GET),已含 meta/data 则原样使用
if not (isinstance(payload, dict) and ("meta" in payload or "data" in payload)):
payload = {"meta": {"method": "GET"}, "data": payload}
client = MQTTClient()
await client.connect("mqtt://localhost:1883/")