Gateway Call
Gateway Call 接口:详细教程
本页聚焦 mosaic gateway call:请求形态、JSON 输出契约、错误处理和自动化模式。
1. 先把 gateway 拉起
mosaic --project-state gateway install --host 127.0.0.1 --port 8787
mosaic --project-state gateway start
mosaic --project-state gateway probe
2. 最小方法调用
mosaic --project-state gateway call status
该命令会把方法 status 透传给 gateway,params 为空。
3. 带 JSON 参数调用
mosaic --project-state gateway call status --params '{"detail":true}'
--params 必须是合法 JSON(对象/数组/字符串),由目标方法解释。
4. 机器可读输出契约
mosaic --project-state --json gateway call status
当前成功返回示例:
{
"ok": true,
"method": "status",
"request_id": "...",
"gateway": { "host": "127.0.0.1", "port": 8787 },
"data": { "ok": true, "service": "mosaic-gateway", "uptime_seconds": 12 }
}
5. probe + call 标准巡检序列
mosaic --project-state --json gateway probe
mosaic --project-state --json gateway call status
mosaic --project-state --json gateway health --verbose
建议把该序列放进 CI 或定时巡检任务。
6. 错误处理建议
probe失败时先gateway restart再 probe。call报协议/网络错误时,先看logs --tail。- 持续失败时执行
doctor并检查状态目录权限。
7. 重启与停机流程
mosaic --project-state gateway restart
mosaic --project-state gateway status --deep
mosaic --project-state gateway stop
8. 自动化脚本示例
# shell 自动化(call 失败则退出非 0)
set -e
mosaic --project-state --json gateway probe >/tmp/gw-probe.json
mosaic --project-state --json gateway call status >/tmp/gw-status.json