You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Benthos同管道内处理器间关键字引用问题求助

Benthos配置错误:request_map找不到send字段的解决方案

问题根源

你的配置存在YAML缩进错误,Benthos对配置的缩进要求非常严格,错误的缩进会导致处理器逻辑不生效:

  1. mapping处理器内的脚本内容没有正确缩进,导致send字段根本没被生成
  2. branch处理器的子配置(request_map、processors、result_map)缩进层级错误,无法正确读取上游消息的字段

修正后的配置

pipeline:
  processors:
    - mapping: |
        root.id = this.id
        root.submitName = "testingAcc"
        root.cost = this.cost
        
        let idLen = root.id.length()
        let nameLen = root.submitName.length()
        root.send = $idLen + root.id + $nameLen + root.submitName + this.cost
    - branch:
        request_map: |
          root = this.send
        processors:
          - http:
              url: "<http link>"
              verb: POST
        result_map: |
          root.response = this.content().string()

关键修正点

  • mapping内的每一行脚本都要缩进4个空格(与mapping:的冒号后对齐),确保脚本被正确解析执行,生成send字段
  • branch的子配置项(request_map、processors、result_map)必须缩进至与branch:的冒号后对齐,保证分支处理器能正确读取上游传递的send字段
  • http处理器的url和verb参数要缩进至与http:对齐,避免HTTP请求配置失效

验证效果

修正后,输入{"id": "1", "cost": "500"}会生成预期的send字段,分支处理器能正确读取该字段发送POST请求,最终输出包含response字段的完整消息:

{"id": "1", "submitName": "testingAcc", "cost": "500", "send": "1110testingAcc500", "response": "OK"}

内容的提问来源于stack exchange,提问作者ravenadows

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 12:52:42