⏱️ Node-RED Delayノード ガイド

このガイドでは、Node-REDのDelayノードについて、初心者の方でも理解できるように詳しく説明します。

📚 1. Delayノードとは?

🤔 「Delay」って何?

Delayノードは、メッセージの送信を遅らせたり、流量を制限したりするノードです。 日常生活で例えると、交通信号機のようなものです。

🚦 交通信号機に例えると:

📦 基本的な動作

Inject Delay
(3秒)
→→→ Debug

Delayノードは、入力メッセージを受け取り、指定した条件に基づいて 遅延させてから出力します。 API呼び出しの間隔調整やセンサーデータの流量制御に活用できます。

⏱️ タイムライン例(3秒遅延):

0秒
入力
1-2秒
⏳ 待機中...
3秒
出力

⚙️ 2. Delayノードの4つの動作モード

遅延 固定遅延

指定した時間だけメッセージを遅らせる

入力 → 3秒待機 → 出力 すべてのメッセージを遅延

ランダム ランダム遅延

指定範囲内でランダムな時間遅延

入力 → 1〜5秒待機 → 出力 テストやシミュレーションに

レート レート制限

メッセージの流量を制限

1秒間に1メッセージのみ通過 キューに蓄積して順次送信

ドロップ トピック別レート

トピックごとに最新メッセージのみ通過

中間メッセージは破棄 最新の状態のみ転送

📋 設定項目一覧

設定項目 説明 対応モード
動作 遅延/レート制限/ドロップから選択 全モード共通
遅延時間 固定の遅延時間を指定 固定遅延
msg.delayで上書き メッセージプロパティで遅延時間を指定 固定遅延
ランダム範囲 最小〜最大の遅延時間 ランダム遅延
レート 時間あたりのメッセージ数 レート制限
中間メッセージを破棄 キューを使わず最新のみ送信 レート制限
レート上書き許可 msg.rateで送信レートを動的に変更 レート制限
トピックごと msg.topicで個別にレート制限 レート制限
名前 ノードの表示名 全モード共通

🎯 特殊なメッセージプロパティ

プロパティ 説明 使用例
msg.delay 遅延時間をミリ秒で上書き msg.delay = 5000(5秒)
msg.rate レートを動的に変更 msg.rate = "2/s"(1秒に2回)
msg.reset キュー内の全メッセージをクリア msg.reset = true
msg.flush キュー内の全メッセージを即座に送信 msg.flush = true
msg.toFront メッセージをキューの先頭に追加 msg.toFront = true

🎯 3. 実用的な使用パターン

📥 サンプルフローのインポート方法:

  1. 下のサンプルフローJSONをコピー
  2. Node-REDエディタで メニュー → 読み込み を選択
  3. JSONをペーストして「読み込み」をクリック

このサンプルフローには、以下で説明する全パターンの実例が含まれています。

📋 サンプルフロー(クリックで展開)

参照元:NodeREDエディター内サンプルフロー

[ { "id": "5de2cee3922f8186", "type": "tab", "label": "delay", "disabled": false, "info": "", "env": [] }, { "id": "c1fce30a7a997845", "type": "comment", "z": "5de2cee3922f8186", "name": "Delay message", "info": "Delay node can delay sending input message to output port by a specified amount of time.", "x": 200, "y": 80, "wires": [] }, { "id": "54c1e915df89ce76", "type": "inject", "z": "5de2cee3922f8186", "name": "", "props": [ {"p": "payload"}, {"p": "topic", "vt": "str"} ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "Hello, World!", "payloadType": "str", "x": 250, "y": 140, "wires": [["28cb0141268e5da4", "61d5ac69a4e4d65b"]] }, { "id": "61d5ac69a4e4d65b", "type": "debug", "z": "5de2cee3922f8186", "name": "即時出力", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 460, "y": 140, "wires": [] }, { "id": "28cb0141268e5da4", "type": "delay", "z": "5de2cee3922f8186", "name": "", "pauseType": "delay", "timeout": "3", "timeoutUnits": "seconds", "rate": "1", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": false, "allowrate": false, "outputs": 1, "x": 440, "y": 200, "wires": [["2bac60bdace9d64f"]] }, { "id": "2bac60bdace9d64f", "type": "change", "z": "5de2cee3922f8186", "name": "Goodbye, World!", "rules": [{"t": "set", "p": "payload", "pt": "msg", "to": "Goodbye, World!", "tot": "str"}], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 630, "y": 200, "wires": [["f2eb7500f8c0d6d3"]] }, { "id": "f2eb7500f8c0d6d3", "type": "debug", "z": "5de2cee3922f8186", "name": "3秒後出力", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 830, "y": 200, "wires": [] }, { "id": "c15b8c3e.955ed", "type": "comment", "z": "5de2cee3922f8186", "name": "Delay message by message property", "info": "Delay node can delay sending input message to output port by a specified amount of time by `msg.delay` property.", "x": 270, "y": 280, "wires": [] }, { "id": "a5ed5817.9df448", "type": "inject", "z": "5de2cee3922f8186", "name": "1秒遅延", "props": [ {"p": "payload"}, {"p": "topic", "vt": "str"}, {"p": "delay", "v": "1000", "vt": "num"} ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "delay 1s", "payloadType": "str", "x": 240, "y": 340, "wires": [["5cf53f4.25b7ec", "59b7b67a.a8e888"]] }, { "id": "59b7b67a.a8e888", "type": "debug", "z": "5de2cee3922f8186", "name": "即時", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 450, "y": 340, "wires": [] }, { "id": "5cf53f4.25b7ec", "type": "delay", "z": "5de2cee3922f8186", "name": "msg.delay使用", "pauseType": "delayv", "timeout": "5", "timeoutUnits": "seconds", "rate": "1", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": false, "allowrate": false, "outputs": 1, "x": 460, "y": 400, "wires": [["fc989f41.c4114"]] }, { "id": "fc989f41.c4114", "type": "change", "z": "5de2cee3922f8186", "name": "Goodbye!", "rules": [{"t": "set", "p": "payload", "pt": "msg", "to": "Goodbye!", "tot": "str"}], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 640, "y": 400, "wires": [["74ba3d1c.666034"]] }, { "id": "74ba3d1c.666034", "type": "debug", "z": "5de2cee3922f8186", "name": "遅延後", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 820, "y": 400, "wires": [] }, { "id": "6cdf7297.bf5a8c", "type": "inject", "z": "5de2cee3922f8186", "name": "10秒遅延", "props": [ {"p": "payload"}, {"p": "topic", "vt": "str"}, {"p": "delay", "v": "10000", "vt": "num"} ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "delay 10s", "payloadType": "str", "x": 240, "y": 400, "wires": [["59b7b67a.a8e888", "5cf53f4.25b7ec"]] }, { "id": "b0200f61.5efa5", "type": "comment", "z": "5de2cee3922f8186", "name": "Reset or flush pending message", "info": "Delay node can reset or flush delayed message by sending it a message with `reset` or `flush` property.", "x": 250, "y": 500, "wires": [] }, { "id": "d5cd8991.e6d2e8", "type": "inject", "z": "5de2cee3922f8186", "name": "メッセージ送信", "props": [{"p": "payload"}, {"p": "topic", "vt": "str"}], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "Hello, World!", "payloadType": "str", "x": 260, "y": 560, "wires": [["607f556b.3ec5fc", "fd14cb.2044db38"]] }, { "id": "fd14cb.2044db38", "type": "debug", "z": "5de2cee3922f8186", "name": "即時", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 450, "y": 560, "wires": [] }, { "id": "607f556b.3ec5fc", "type": "delay", "z": "5de2cee3922f8186", "name": "10秒遅延", "pauseType": "delay", "timeout": "10", "timeoutUnits": "seconds", "rate": "1", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": false, "allowrate": false, "outputs": 1, "x": 450, "y": 620, "wires": [["d1fc6763.2a30c8"]] }, { "id": "d1fc6763.2a30c8", "type": "change", "z": "5de2cee3922f8186", "name": "Goodbye!", "rules": [{"t": "set", "p": "payload", "pt": "msg", "to": "Goodbye!", "tot": "str"}], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 620, "y": 620, "wires": [["15486d4a.80c6f3"]] }, { "id": "15486d4a.80c6f3", "type": "debug", "z": "5de2cee3922f8186", "name": "10秒後", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 800, "y": 620, "wires": [] }, { "id": "2b8b28c7.4c8978", "type": "inject", "z": "5de2cee3922f8186", "name": "reset", "props": [{"p": "topic", "vt": "str"}, {"p": "reset", "v": "true", "vt": "bool"}], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "x": 230, "y": 620, "wires": [["607f556b.3ec5fc"]] }, { "id": "3a7e1bec.8bc3d4", "type": "inject", "z": "5de2cee3922f8186", "name": "flush", "props": [{"p": "topic", "vt": "str"}, {"p": "flush", "v": "true", "vt": "bool"}], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "x": 230, "y": 680, "wires": [["607f556b.3ec5fc"]] }, { "id": "2d14f1a7.e776ce", "type": "comment", "z": "5de2cee3922f8186", "name": "Slow down messages passing through a flow", "info": "Delay node can be used to slow down messages passing through a flow.", "x": 290, "y": 760, "wires": [] }, { "id": "af78b43e.9817d8", "type": "inject", "z": "5de2cee3922f8186", "name": "配列送信", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "[0,1,2,3,4,5,6,7,8,9]", "payloadType": "json", "x": 240, "y": 820, "wires": [["a35943e3.eaf0a"]] }, { "id": "a35943e3.eaf0a", "type": "split", "z": "5de2cee3922f8186", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 390, "y": 820, "wires": [["23eacc60.7290a4"]] }, { "id": "23eacc60.7290a4", "type": "delay", "z": "5de2cee3922f8186", "name": "1msg/秒", "pauseType": "rate", "timeout": "5", "timeoutUnits": "seconds", "rate": "1", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": false, "allowrate": false, "outputs": 1, "x": 520, "y": 820, "wires": [["b5b7746a.53bf88"]] }, { "id": "b5b7746a.53bf88", "type": "debug", "z": "5de2cee3922f8186", "name": "1秒ごと", "active": true, "tosidebar": true, "console": false, "tostatus": true, "complete": "payload", "targetType": "msg", "x": 660, "y": 820, "wires": [] }, { "id": "3dc5015b.96c97e", "type": "comment", "z": "5de2cee3922f8186", "name": "Limit rate of message transfer for each topic", "info": "Delay node can limit of message transmission from input to output port by a specified number of message per a specified time.", "x": 290, "y": 900, "wires": [] }, { "id": "bdafe4c6.4d5658", "type": "inject", "z": "5de2cee3922f8186", "name": "トピック別データ", "props": [{"p": "payload"}, {"p": "topic", "vt": "str"}], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "[{\"topic\":\"apple\",\"payload\":1},{\"topic\":\"apple\",\"payload\":2},{\"topic\":\"apple\",\"payload\":3},{\"topic\":\"orange\",\"payload\":1},{\"topic\":\"orange\",\"payload\":2},{\"topic\":\"orange\",\"payload\":3},{\"topic\":\"banana\",\"payload\":1},{\"topic\":\"banana\",\"payload\":2},{\"topic\":\"banana\",\"payload\":3}]", "payloadType": "json", "x": 260, "y": 960, "wires": [["f86dc462.195818"]] }, { "id": "f86dc462.195818", "type": "split", "z": "5de2cee3922f8186", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 410, "y": 960, "wires": [["9feb3aac.616c38"]] }, { "id": "9feb3aac.616c38", "type": "change", "z": "5de2cee3922f8186", "name": "topic設定", "rules": [ {"t": "set", "p": "topic", "pt": "msg", "to": "payload.topic", "tot": "msg"}, {"t": "set", "p": "payload", "pt": "msg", "to": "payload.payload", "tot": "msg"} ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 560, "y": 960, "wires": [["e0bdfcc1.cdf48"]] }, { "id": "e0bdfcc1.cdf48", "type": "delay", "z": "5de2cee3922f8186", "name": "トピック別最新", "pauseType": "timed", "timeout": "5", "timeoutUnits": "seconds", "rate": "1", "nbRateUnits": "2", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": true, "allowrate": false, "outputs": 1, "x": 740, "y": 960, "wires": [["29d8beea.6b37f2"]] }, { "id": "29d8beea.6b37f2", "type": "debug", "z": "5de2cee3922f8186", "name": "最新のみ", "active": true, "tosidebar": true, "console": false, "tostatus": true, "complete": "false", "x": 920, "y": 960, "wires": [] } ]

パターン1: 固定時間の遅延

用途: メッセージを指定した秒数だけ遅らせる

Inject Delay
(3秒)
Debug

📌 動作の流れ:

  1. Injectボタンをクリック → "Hello, World!" を送信
  2. Delayノードで3秒間保持
  3. 3秒後にDebugに出力

設定例:

動作: 一定時間遅延させる 遅延時間: 3秒 入力: 10:00:00 に "Hello, World!" 出力: 10:00:03 に "Hello, World!"(3秒後)

パターン2: msg.delayによる動的遅延

用途: メッセージごとに異なる遅延時間を設定

Inject
(delay=1000)
Delay
(msg.delay)
Debug

Inject
(delay=10000)

📌 msg.delayの単位:

設定例:

動作: msg.delayに指定した時間遅延 (設定画面で「msg.delayで上書き」を選択) メッセージ1: msg.delay = 1000 → 1秒後に出力 メッセージ2: msg.delay = 10000 → 10秒後に出力

パターン3: Reset/Flushによる制御

用途: 待機中のメッセージをクリアまたは即座に送信

メッセージ Delay
(10秒)
Debug

reset
flush

📌 Reset vs Flush:

設定例:

Resetの場合: 1. メッセージを送信(10秒遅延開始) 2. 5秒後にresetを送信 3. 待機中のメッセージは破棄される(出力なし) Flushの場合: 1. メッセージを送信(10秒遅延開始) 2. 5秒後にflushを送信 3. 待機中のメッセージが即座に出力される

パターン4: レート制限(流量制御)

用途: メッセージの送信速度を制限

配列
[0-9]
Split →→→ Delay
(1msg/秒)
Debug

⏱️ レート制限の動作:

入力
0,1,2,3,4...一斉に
出力
0
1
2
3
...

↑ 1秒ごとに1メッセージずつ出力

設定例:

動作: メッセージのレートを制限 レート: 1メッセージ / 1秒 入力: 10個のメッセージを一斉に送信 出力: 1秒ごとに1メッセージずつ出力(10秒かかる)

パターン5: トピック別レート制限

用途: トピックごとに最新メッセージのみを通過

データ Split topic設定 Delay
(トピック別)
Debug

📌 トピック別レート制限の動作:

設定例:

動作: トピックごとに最新メッセージを送信 レート: 1メッセージ / 2秒 中間メッセージを破棄: ✓ 入力: apple:1 → apple:2 → apple:3 orange:1 → orange:2 → orange:3 banana:1 → banana:2 → banana:3 出力(2秒後): apple:3(最新のみ) orange:3(最新のみ) banana:3(最新のみ)

🏋️ 4. 実践演習

演習1: 基本的な遅延初級

📝 課題:

メッセージを5秒遅延させて出力するフローを作成してください。

🎯 要求仕様:

📊 期待される動作:

✅ 成功の条件:

💡 ヒント

Injectノードの設定:

  • payload: 文字列 "遅延テスト"

Delayノードの設定:

  • 動作: 一定時間遅延させる
  • 遅延時間: 5秒

Debugノードの設定:

  • 出力: msg.payload
✅ 解答例フロー
[ { "id": "ex1_inject", "type": "inject", "name": "遅延テスト", "props": [{"p": "payload"}], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "遅延テスト", "payloadType": "str", "x": 140, "y": 100, "wires": [["ex1_delay"]] }, { "id": "ex1_delay", "type": "delay", "name": "5秒遅延", "pauseType": "delay", "timeout": "5", "timeoutUnits": "seconds", "rate": "1", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": false, "allowrate": false, "outputs": 1, "x": 300, "y": 100, "wires": [["ex1_debug"]] }, { "id": "ex1_debug", "type": "debug", "name": "結果", "active": true, "tosidebar": true, "console": false, "tostatus": true, "complete": "payload", "targetType": "msg", "x": 450, "y": 100, "wires": [] } ]

演習2: 動的遅延の実装中級

📝 課題:

優先度に応じて遅延時間を変える仕組みを作成してください。

🎯 要求仕様:

📊 期待される動作:

✅ 成功の条件:

💡 ヒント

Inject(高優先度)の設定:

  • payload: "高優先度メッセージ"
  • delay: 1000(数値)

Inject(低優先度)の設定:

  • payload: "低優先度メッセージ"
  • delay: 5000(数値)

Delayノードの設定:

  • 動作: msg.delayに指定した時間遅延
✅ 解答例フロー
[ { "id": "ex2_inject_high", "type": "inject", "name": "高優先度", "props": [ {"p": "payload", "v": "高優先度メッセージ", "vt": "str"}, {"p": "delay", "v": "1000", "vt": "num"} ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "x": 140, "y": 80, "wires": [["ex2_delay"]] }, { "id": "ex2_inject_low", "type": "inject", "name": "低優先度", "props": [ {"p": "payload", "v": "低優先度メッセージ", "vt": "str"}, {"p": "delay", "v": "5000", "vt": "num"} ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "x": 140, "y": 140, "wires": [["ex2_delay"]] }, { "id": "ex2_delay", "type": "delay", "name": "動的遅延", "pauseType": "delayv", "timeout": "5", "timeoutUnits": "seconds", "rate": "1", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": false, "allowrate": false, "outputs": 1, "x": 320, "y": 110, "wires": [["ex2_debug"]] }, { "id": "ex2_debug", "type": "debug", "name": "結果", "active": true, "tosidebar": true, "console": false, "tostatus": true, "complete": "payload", "targetType": "msg", "x": 470, "y": 110, "wires": [] } ]

演習3: APIレート制限シミュレーション中級

📝 課題:

1秒に2回までしかAPIを呼べない制限をシミュレートしてください。

🎯 要求仕様:

📊 期待される動作:

✅ 成功の条件:

💡 ヒント

Injectノードの設定:

  • payload: JSON型で [1,2,3,4,5,6,7,8,9,10]

Splitノードの設定:

  • デフォルト設定でOK(配列を分割)

Delayノードの設定:

  • 動作: メッセージのレートを制限
  • レート: 2メッセージ / 1秒
✅ 解答例フロー
[ { "id": "ex3_inject", "type": "inject", "name": "10件送信", "props": [{"p": "payload"}], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "[1,2,3,4,5,6,7,8,9,10]", "payloadType": "json", "x": 140, "y": 100, "wires": [["ex3_split"]] }, { "id": "ex3_split", "type": "split", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 290, "y": 100, "wires": [["ex3_delay"]] }, { "id": "ex3_delay", "type": "delay", "name": "2msg/秒", "pauseType": "rate", "timeout": "5", "timeoutUnits": "seconds", "rate": "2", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": false, "allowrate": false, "outputs": 1, "x": 420, "y": 100, "wires": [["ex3_debug"]] }, { "id": "ex3_debug", "type": "debug", "name": "API呼び出し", "active": true, "tosidebar": true, "console": false, "tostatus": true, "complete": "payload", "targetType": "msg", "x": 570, "y": 100, "wires": [] } ]

演習4: センサーデータのサンプリング上級

📝 課題:

複数センサーからの高頻度データを、センサーごとに最新値のみ定期送信する仕組みを作成してください。

🎯 要求仕様:

📊 期待される動作:

✅ 成功の条件:

💡 ヒント

Injectノードの設定:

  • JSON配列でセンサーデータをシミュレート
  • 各データにtopicを設定

Splitノードの設定:

  • デフォルト設定でOK

Changeノードの設定:

  • msg.topic = msg.payload.sensor
  • msg.payload = msg.payload.value

Delayノードの設定:

  • 動作: メッセージのレートを制限
  • レート: 1メッセージ / 3秒
  • 中間メッセージを破棄: ✓
  • トピックごと: ✓
✅ 解答例フロー
[ { "id": "ex4_inject", "type": "inject", "name": "センサーデータ", "props": [{"p": "payload"}], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "[{\"sensor\":\"temp\",\"value\":25.1},{\"sensor\":\"temp\",\"value\":25.2},{\"sensor\":\"temp\",\"value\":25.3},{\"sensor\":\"humidity\",\"value\":60},{\"sensor\":\"humidity\",\"value\":61},{\"sensor\":\"humidity\",\"value\":62},{\"sensor\":\"pressure\",\"value\":1013},{\"sensor\":\"pressure\",\"value\":1014},{\"sensor\":\"pressure\",\"value\":1015}]", "payloadType": "json", "x": 160, "y": 100, "wires": [["ex4_split"]] }, { "id": "ex4_split", "type": "split", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 310, "y": 100, "wires": [["ex4_change"]] }, { "id": "ex4_change", "type": "change", "name": "topic設定", "rules": [ {"t": "set", "p": "topic", "pt": "msg", "to": "payload.sensor", "tot": "msg"}, {"t": "set", "p": "payload", "pt": "msg", "to": "payload.value", "tot": "msg"} ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 460, "y": 100, "wires": [["ex4_delay"]] }, { "id": "ex4_delay", "type": "delay", "name": "トピック別最新", "pauseType": "timed", "timeout": "5", "timeoutUnits": "seconds", "rate": "1", "nbRateUnits": "3", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": true, "allowrate": false, "outputs": 1, "x": 620, "y": 100, "wires": [["ex4_debug"]] }, { "id": "ex4_debug", "type": "debug", "name": "最新値のみ", "active": true, "tosidebar": true, "console": false, "tostatus": true, "complete": "true", "targetType": "full", "x": 790, "y": 100, "wires": [] } ]

🎓 5. まとめ

Delayノードの重要ポイント

⚠️ よくある間違い

📚 次のステップ

Delayノードをマスターしたら、以下のノードも学んでみましょう:

🔧 6. トラブルシューティング

よくある問題と解決方法

問題 原因 解決方法
メッセージが出力されない 遅延時間が長すぎる 遅延時間を確認、flushで強制出力
msg.delayが効かない モードが固定遅延になっている 「msg.delayで上書き」を選択
メモリ使用量が増加 レート制限でキューが蓄積 ドロップモードを使用、またはresetで定期クリア
再起動後にメッセージが消えた キューは永続化されない 重要なメッセージは別途保存
トピック別が動作しない msg.topicが設定されていない Changeノードでmsg.topicを設定
flushしても出力されない キューが空 メッセージがキューに入っているか確認

💡 7. 実務での活用例

ケース1: API呼び出しのレート制限

外部API(1秒に10回まで)への連続リクエスト ↓ Delayノード(レート: 10msg/秒) ↓ HTTP Request → API呼び出し ↓ レート制限エラーを回避しながら大量処理

ケース2: センサーデータのサンプリング

温度センサー(100ms間隔で送信) ↓ Delayノード(トピック別、1msg/5秒、ドロップ) ↓ 最新値のみ5秒ごとにダッシュボードに表示 ↓ 通信量とCPU負荷を大幅削減

ケース3: IoTデバイスの起動シーケンス

Raspberry Pi起動 ↓ Delay 10秒(ネットワーク接続待ち) ↓ Delay 5秒(センサー初期化待ち) ↓ メイン処理開始 ※ 起動直後の不安定な状態を回避

ケース4: 通知のバースト防止

アラート発生(短時間に大量) ↓ Delayノード(レート: 1msg/分) ↓ メール/Slack通知 ↓ 通知の洪水を防止、最新の状態を伝達

📖 8. 詳細設定リファレンス

遅延時間の単位

単位 設定値 msg.delay換算
ミリ秒 milliseconds そのまま
seconds × 1000
minutes × 60000
時間 hours × 3600000
days × 86400000

ノードステータスの意味

⏳ 3 queued = キューに3メッセージ待機中
🟢 rate limited = レート制限が有効

🔗 9. 追加リソース


このガイドが役に立ちましたら、実際のプロジェクトで練習してみてください!
Delayノードはフロー制御とAPI連携に欠かせないツールです。

参照元:NodeREDエディター内サンプルフロー

🏠