【问题标题】:How can I run parallel flows in node-red and then join the data?如何在 node-red 中运行并行流,然后加入数据?
【发布时间】:2018-09-14 00:27:58
【问题描述】:

我有一个节点红色的流程,我需要进行 2 次休息调用,然后根据这两次调用的结果进行一些数据操作。

我解决这个问题的唯一方法是一个接一个地进行两个调用

有没有办法在 node-red 中分支一个流,然后像这样再次加入 上面的函数节点将被调用两次。我需要的是一个具有多个输入的节点,然后等待每个 msg.payload 到达,然后再开始处理。

谢谢

【问题讨论】:

标签: node-red


【解决方案1】:

这是可能的,使用拆分和连接节点。

看看这个例子:

[{"id":"8eb8c9c4.605e88","type":"http in","z":"abe521f2.f083a","name":"","url":"/parallel", "方法":"get","upload":false,"swaggerDoc":"","x":124.5,"y":632,"wires":[["dff9f95f.6f84f8"]]},{" id":"dff9f95f.6f84f8","type":"change","z":"abe521f2.f083a","name":"","rules":[{"t":"set","p ":"payload","pt":"msg","to":"{\"httpbin\":\"http://httpbin.org/get\",\"anything\":\"http://httpbin.org/anything/get\"}", "tot":"json"}],"action":"","property":"","from":"","to":"","re​​g":false,"x":356.5, "y":631,"wires":[["4b5a9dfb.439594"]]},{"id":"4b5a9dfb.439594","type":"split","z":"abe521f2.f083a", "name":"","splt":"\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic ","x":526.5,"y":631,"wires":[["8238bd1f.80e7f"]]},{"id":"8238bd1f.80e7f","type":"switch","z ":"abe521f2.f083a","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":" httpbin","vt":"str"},{"t":"eq","v":"anything","vt":"str"}],"checkall":"true","outputs" :2,"x":655.5,"y":631,"wires":[["ada1d5f5.b43148"],["7400821e.6dd82c"]]},{ "id":"ada1d5f5.b43148","type":"http 请求","z":"abe521f2.f083a","name":"REST 服务 1","method":"GET","re​​t" :"obj","url":"{{{payload}}}","tls":"","x":833.5,"y":590,"wires":[["99c15809.ccd4c8"] ]},{"id":"7400821e.6dd82c","type":"http 请求","z":"abe521f2.f083a","name":"REST 服务 2","method":"GET" ,"ret":"obj","url":"http://httpbin.org/anything/get","tls":"","x":834,"y":672,"wires":[["99c15809.ccd4c8"] ]},{"id":"99c15809.ccd4c8","type":"join","z":"abe521f2.f083a","name":"","mode":"auto","build" :"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\n","joinerType":"str","accumulate": "false","timeout":"","count":"","x":1015.5,"y":626,"wires":[["6a617e7c.5a6de"]]},{"id": "6a617e7c.5a6de","type":"http 响应","z":"abe521f2.f083a","name":"","statusCode":"","headers":{},"x": 1162,"y":626,"电线":[]}]

【讨论】:

  • 答案信息不足。您将如何使用现有功能执行 Join 节点? msg.parts 的返回负载似乎没有文档。
  • 这个例子使用了一个带有 switch 节点的 split 函数,它本质上是根据条件调用 API 的某个部分。我相信这不是并行处理。
【解决方案2】:

不知道这对您来说是否仍然是一个问题,但请查看此节点。 它等待配置的 msg.paths["pathname"] 并将它们合并到 msg.paths 中

https://flows.nodered.org/node/node-red-contrib-wait-paths

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 2022-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-25
    相关资源
    最近更新 更多