本页内容
Sommatic 文档
打开控制台

gRPC Client

调用 gRPC 服务方法。

以 Markdown 查看
在以下应用中打开
输入与输出 可用 io.grpc 版本 1.0.0 执行方式: async

调用 gRPC 服务的一个一元方法,服务由编排器可访问的 .proto 文件描述,主机和 proto 设置取自凭据。

工作原理

  1. 解析配置。connection_id、service 和 method 缺失时回退到输入 payload 中的同名键。
  2. 构建请求消息:配置的 payload 为非空对象时使用它;否则使用输入数据中的 payload.payload,或整个输入数据。
  3. 解析凭据配置:host(host:port)、protoPath(编排器文件系统上的文件)、可选的 packageName 和 secure。
  4. 加载 proto(保留字段原始名称,long 和 enum 转为字符串,并填充默认值),依次查找 packageName 与 service;secure 为 true 时建立 TLS 通道,否则建立明文通道。
  5. 以该消息调用 method;若密钥含 token,则附带元数据 Authorization: Bearer <token>。响应以 { response } 从 out 输出。

在工作流中

节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。

{
  "node_id": "node-confirm-order",
  "label": "Confirm order",
  "operator_slug": "io.grpc",
  "operator_version": "1.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "service": "OrderService",
    "method": "ConfirmOrder",
    "payload": {
      "order_id": "{{ $json.order_id }}"
    }
  }
}

配置

connection_id string 必填

gRPC 端点的凭据。接受 `certificate`(用于 mTLS 的 TLS 证书 + 密钥)或 `object`(主机 + .proto 路径 + 高级配置)类型的凭据。

service string 必填

服务名称

method string 必填

方法名称

payload object 可选

请求消息

代码中的行为

除 schema 描述之外,实现代码对这些键的实际处理。

connection_id
凭据配置须包含 host、protoPath、可选的 packageName 和 secure;密钥中只读取 token。选择器接受 certificate 凭据,但不会使用客户端证书:TLS 使用系统信任库且不带客户端证书(不支持 mTLS)。
payload
请求消息。空对象视为未设置,此时改为发送输入数据。

输出端口

out 默认

方法返回了响应。response 为解码后的响应消息。

数据
{
  "response": {
    "order_id": "ord_123",
    "status": "CONFIRMED",
    "total_cents": "25000"
  }
}
error

调用返回 gRPC 状态错误(数据为 { error, code },含数字 gRPC 状态码),或准备阶段失败(数据为 { error })。

数据
{
  "error": "14 UNAVAILABLE: No connection established",
  "code": 14
}

在表达式中

后续节点可通过 $("gRPC Client").item.json.<路径> 读取此节点输出中的内容(请把 gRPC Client 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 out 返回的路径,依据“端口”一节所示的输出。

表达式EditorWorker
$("gRPC Client").item.json.responseobject= {…}gRPC 响应消息
$("gRPC Client").item.json.response.order_idstring编辑器不提示= "ord_123"—
$("gRPC Client").item.json.response.statusstring编辑器不提示= "CONFIRMED"—
$("gRPC Client").item.json.response.total_centsstring编辑器不提示= "25000"—

— Worker: worker 会返回它,但编辑器不会提示:请手动输入。对象内部的键可能取决于你的数据或配置(例如每个标签一个键)。

错误

消息 端口 原因与处理
protoPath missing in connection config error 凭据配置中缺少 protoPath。请添加编排器主机上存在的 .proto 文件路径。
Package <packageName> not found in proto error packageName 与 proto 的顶层包不匹配。只查找单段名称(例如 helloworld,而非 acme.orders)。
Service <service> not found error 所选包中未定义 service。
Method <method> not found error method 不是该服务的方法。请使用 proto 中的原始名称。
connection_id is required error 未选择凭据。

输入契约

connection_id string 必填
service string 必填
method string 必填
payload object 可选

输出契约

response object 可选

gRPC 响应消息

契约(JSON Schema)

与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。

{
  "slug": "io.grpc",
  "name": "gRPC Client",
  "category": "io",
  "version": "1.0.0",
  "description": "Call gRPC Service method.",
  "capabilities": [
    "grpc",
    "microservices",
    "protobuf"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string",
        "title": "gRPC Credential",
        "description": "Credential for the gRPC endpoint. Accepts credentials of type `certificate` (TLS cert + key for mTLS) or `object` (host + .proto path + advanced config).",
        "ui_widget": "connection_picker",
        "ui_options": {
          "credential_types": [
            "certificate",
            "object"
          ],
          "types": [
            "grpc"
          ]
        }
      },
      "service": {
        "type": "string",
        "description": "Service Name"
      },
      "method": {
        "type": "string",
        "description": "Method Name"
      },
      "payload": {
        "type": "object",
        "description": "Request Message"
      }
    },
    "required": [
      "connection_id",
      "service",
      "method"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string"
      },
      "service": {
        "type": "string"
      },
      "method": {
        "type": "string"
      },
      "payload": {
        "type": "object"
      }
    },
    "required": [
      "connection_id",
      "service",
      "method"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "response": {
        "type": "object",
        "description": "gRPC Response Message"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Response",
      "description": "gRPC Response Message",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "gRPC Error Code",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "standard-io",
    "microservices"
  ],
  "tags": [
    "grpc",
    "rpc"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_link_loom",
    "profile": {
      "name": "Link Loom",
      "verified": true,
      "url": "https://me.veripass.com/link-loom",
      "logo_url": null
    }
  }
}

执行

执行方式
async
有状态
否
凭据
在服务器端根据 connection_id 解析,密钥不会进入工作流。
能力
grpcmicroservicesprotobuf
标签
grpcrpc

说明与限制

  • 仅支持一元调用,不处理流式方法。调用未设置截止时间,也不会重试。
  • .proto 文件在每次运行时从编排器文件系统读取,不会随工作流上传。
  • response 中的 64 位整数和枚举以字符串形式返回。

已对照编排器代码核实 · 31e874b · 2026-11-26

安装智能体工具

为你的编程智能体接入 Sommatic AI 官方文档:技能包、文档 MCP 服务器与 Markdown 页面,无需再抓取网页。

仅安装技能包,不会自动更新;需要时重新运行即可。

npx skills add https://docs.sommatic.ai
智能体如何读取本文档