跳到主要内容

流程控制-降低消息通过速率

降低通过流测消息速率

问题背景

降低消息在流中的传输速度。例如,一条包含值数组的消息,将其拆分成一个消息流,并希望以每秒一条消息的速度处理该流中的每条消息。

解决方案

使用 延迟 节点来限制通过它的消息的速率。

示例

slow-down-msg-pass-through

示例JSON

[{"id":"1fccc223.7ba87e","type":"inject","z":"e028a121bc4ae061","name":"Inject Array","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[0,1,2,3,4,5,6,7,8,9]","payloadType":"json","x":180,"y":1480,"wires":[["b2837466.e02a38"]]},{"id":"b2837466.e02a38","type":"split","z":"e028a121bc4ae061","name":"拆分数组","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":330,"y":1480,"wires":[["bd97c8ed.a5c8d8"]]},{"id":"bd97c8ed.a5c8d8","type":"delay","z":"e028a121bc4ae061","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":510,"y":1480,"wires":[["bd66f03e.bdf0c"]]},{"id":"bd66f03e.bdf0c","type":"debug","z":"e028a121bc4ae061","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":690,"y":1480,"wires":[]}]

运行结果

点击 注入 节点按钮,将会看到 1s 输出一个数组元素,限制 1msg/s 延迟节点下方有一个蓝色方块和倒数,直到倒数为0输出停止

slow-down-msg-pass-through-result