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

Queue / Topic Consumer

从外部消息队列或 Pub/Sub 主题消费消息。

以 Markdown 查看
在以下应用中打开
触发器 实验性 queue.trigger 版本 1.0.0 执行方式: async

队列驱动工作流的入口节点。它将运行输入整理为 { message_id, queue, content, attributes },并拒绝来自 subscription 以外队列的消息;当前版本中没有消息代理消费者会启动它。

该触发器连接外部消息代理(如 RabbitMQ、Kafka、SQS 或 Redis),并为每条传入消息启动一个工作流实例。

主要特性:

  • 背压: 支持 prefetch,以限制并发创建的工作流实例数。
  • 可靠性: 支持自动或手动确认(Ack/Nack),保证消息投递。

适用场景:

  • 处理从主 Web 服务器卸载出来的任务。
  • 与遗留系统集成的事件驱动架构。

工作原理

  1. 触发来源:当前版本中没有后端组件为本节点消费消息代理。只有以 { message_id, queue, content, attributes } 结构的输入显式启动工作流时才会运行。
  2. 解析节点配置。若设置了 subscription,且输入中的 queue 存在但与之不同,则返回 error。
  3. 否则输出 message_id(默认 unknown)、queue(取输入值或 subscription)、content(取输入的 content,否则为整个输入)和 attributes(默认 {})。

在工作流中

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

{
  "node_id": "node-orders-queue",
  "label": "Orders queue",
  "operator_slug": "queue.trigger",
  "operator_version": "1.0.0",
  "config": {
    "source": "pi-credential-xxxx",
    "subscription": "orders.created",
    "prefetch": 10,
    "ack_mode": "auto"
  }
}

配置

source string 必填

消息代理连接的资源 ID。

subscription string 必填

要监听的具体通道。

prefetch integer 可选

未确认消息的最大数量。

默认值: 10

ack_mode string 可选

Auto:工作流启动时确认。Manual:需要由特定应用确认。

默认值: auto

可选值: automanual

配置中会显示通用执行设置,但该节点目前不执行重试(retryOnFail、maxTries)。所有节点均未实现 continueOnFail。

代码中的行为

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

source
已声明且为必填,但不会被读取。prefetch 和 ack_mode 同样不会被读取:本节点不会确认(ack)任何消息。
subscription
仅用于拒绝来自其他队列的消息,并作为输出中 queue 的默认值。

输出端口

out 默认

消息被接受。

数据
{
  "message_id": "msg-7f3a9c",
  "queue": "orders.created",
  "content": {
    "order_id": "ord_123",
    "total": 129.99
  },
  "attributes": {
    "content-type": "application/json"
  }
}
error

输入中的 queue 与 subscription 不一致。输出为信封 { ok, errors, port }。

数据
{
  "ok": false,
  "errors": [
    "Queue mismatch: orders.created is not equal to orders.cancelled"
  ],
  "port": "error"
}

在表达式中

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

表达式EditorWorker
$("Queue / Topic Consumer").item.json.message_idstring= "msg-7f3a9c"
$("Queue / Topic Consumer").item.json.queuestring= "orders.created"
$("Queue / Topic Consumer").item.json.contentobject= {…}消息正文。
$("Queue / Topic Consumer").item.json.attributesobject= {…}消息头/元数据。
$("Queue / Topic Consumer").item.json.content.order_idstring编辑器不提示= "ord_123"—
$("Queue / Topic Consumer").item.json.content.totalnumber编辑器不提示= 129.99—
$("Queue / Topic Consumer").item.json.attributes.content-typestring编辑器不提示= "application/json"—

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

错误

消息 端口 原因与处理
Queue mismatch: <subscription> is not equal to <queue> error 工作流以来自其他队列的消息启动。

输出契约

message_id string 可选
queue string 可选
content object 可选

消息正文。

attributes object 可选

消息头/元数据。

契约(JSON Schema)

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

{
  "slug": "queue.trigger",
  "name": "Queue / Topic Consumer",
  "category": "triggers",
  "version": "1.0.0",
  "description": "Consumes messages from an external Message Queue or Pub/Sub Topic.\n\n  This trigger connects to external brokers (like RabbitMQ, Kafka, SQS, or Redis) and initiates a workflow instance for each incoming message.\n\n  **Key Features:**\n  - **Backpressure:** Supports `prefetch` to limit concurrent workflow instantiations.\n  - **Reliability:** Supports Auto or Manual Acknowledgement (Ack/Nack) to ensure message delivery guarantees.\n\n  **Use Cases:**\n  - Processing tasks offloaded from a main web server.\n  - Event-driven architecture integrating with legacy systems.",
  "capabilities": [
    "queue-consumer",
    "high-throughput",
    "async-processing"
  ],
  "config_schema": {
    "type": "object",
    "required": [
      "source",
      "subscription"
    ],
    "properties": {
      "source": {
        "type": "string",
        "title": "Connection / Broker",
        "description": "Resource ID of the message broker connection."
      },
      "subscription": {
        "type": "string",
        "title": "Queue Name / Topic",
        "description": "The specific channel to listen to."
      },
      "prefetch": {
        "type": "integer",
        "default": 10,
        "title": "Prefetch Count",
        "description": "Max unacknowledged messages."
      },
      "ack_mode": {
        "type": "string",
        "enum": [
          "auto",
          "manual"
        ],
        "default": "auto",
        "title": "Ack Mode",
        "description": "Auto: Ack on workflow start. Manual: Requires specific app to Ack."
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    }
  },
  "input_contract_schema": null,
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "message_id": {
        "type": "string"
      },
      "queue": {
        "type": "string"
      },
      "content": {
        "type": "object",
        "description": "The message body."
      },
      "attributes": {
        "type": "object",
        "description": "Message headers/metadata."
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Message Received",
      "is_default": true
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "async",
  "tags": [
    "queue",
    "consumer",
    "kafka",
    "rabbitmq"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}

执行

执行方式
async
有状态
否
重试(retryOnFail)
否
能力
queue-consumerhigh-throughputasync-processing
标签
queueconsumerkafkarabbitmq

说明与限制

  • 输入中没有 content 时,整个输入(包括后端可能添加的 $trigger_state)都会成为 content。
  • 使用示例数据时,引擎会跳过本节点,并经 out 原样输出示例输入。

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

安装智能体工具

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

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

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