Last active
December 13, 2017 16:31
-
-
Save natcl/b9c254e08e874036785ba31ec5a8b773 to your computer and use it in GitHub Desktop.
MQTT JSON RPC Request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": "64220941.ddbd78", | |
"type": "subflow", | |
"name": "mqtt request", | |
"info": "", | |
"in": [ | |
{ | |
"x": 60, | |
"y": 220, | |
"wires": [ | |
{ | |
"id": "4cd25727.66fb2" | |
} | |
] | |
} | |
], | |
"out": [ | |
{ | |
"x": 1020, | |
"y": 80, | |
"wires": [ | |
{ | |
"id": "56a8e6c7.07c12", | |
"port": 0 | |
} | |
] | |
} | |
] | |
}, | |
{ | |
"id": "65fc5e3e.76801", | |
"type": "mqtt out", | |
"z": "64220941.ddbd78", | |
"name": "", | |
"topic": "", | |
"qos": "", | |
"retain": "", | |
"broker": "efdb112b.a66a7", | |
"x": 810, | |
"y": 220, | |
"wires": [] | |
}, | |
{ | |
"id": "1f689bd2.79d1f4", | |
"type": "mqtt in", | |
"z": "64220941.ddbd78", | |
"name": "", | |
"topic": "project/+/resp", | |
"qos": "2", | |
"broker": "efdb112b.a66a7", | |
"x": 130, | |
"y": 80, | |
"wires": [ | |
[ | |
"1f981dde.8d9ff2" | |
] | |
] | |
}, | |
{ | |
"id": "1f981dde.8d9ff2", | |
"type": "json", | |
"z": "64220941.ddbd78", | |
"name": "", | |
"pretty": false, | |
"x": 290, | |
"y": 80, | |
"wires": [ | |
[ | |
"9585233e.ccc618" | |
] | |
] | |
}, | |
{ | |
"id": "a47b6bd2.49dee8", | |
"type": "delay", | |
"z": "64220941.ddbd78", | |
"name": "", | |
"pauseType": "delay", | |
"timeout": "1", | |
"timeoutUnits": "seconds", | |
"rate": "1", | |
"nbRateUnits": "1", | |
"rateUnits": "second", | |
"randomFirst": "1", | |
"randomLast": "5", | |
"randomUnits": "seconds", | |
"drop": false, | |
"x": 540, | |
"y": 160, | |
"wires": [ | |
[ | |
"c77febe8.313ac8" | |
] | |
] | |
}, | |
{ | |
"id": "4cd25727.66fb2", | |
"type": "json-schema-validator", | |
"z": "64220941.ddbd78", | |
"name": "RPC Schema validation", | |
"func": "{\n \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n \"description\": \"A JSON RPC 2.0 request\",\n \"oneOf\": [\n {\n \"description\": \"An individual request\",\n \"$ref\": \"#/definitions/request\"\n },\n {\n \"description\": \"An array of requests\",\n \"type\": \"array\",\n \"items\": { \"$ref\": \"#/definitions/request\" }\n }\n ],\n \"definitions\": {\n \"request\": {\n \"type\": \"object\",\n \"required\": [ \"jsonrpc\", \"method\" ],\n \"properties\": {\n \"jsonrpc\": { \"enum\": [ \"2.0\" ] },\n \"method\": {\n \"type\": \"string\"\n },\n \"id\": {\n \"type\": [ \"string\", \"number\", \"null\" ],\n \"note\": [\n \"While allowed, null should be avoided: http://www.jsonrpc.org/specification#id1\",\n \"While allowed, a number with a fractional part should be avoided: http://www.jsonrpc.org/specification#id2\"\n ]\n },\n \"params\": {\n \"type\": [ \"array\", \"object\" ]\n }\n }\n }\n }\n}", | |
"x": 290, | |
"y": 220, | |
"wires": [ | |
[ | |
"69d3027b.46dd1c", | |
"a47b6bd2.49dee8" | |
] | |
] | |
}, | |
{ | |
"id": "9585233e.ccc618", | |
"type": "json-schema-validator", | |
"z": "64220941.ddbd78", | |
"name": "RPC Schema answer validation", | |
"func": "{\n \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n \"description\": \"A JSON RPC 2.0 response\",\n \"oneOf\": [\n { \"$ref\": \"#/definitions/success\" },\n { \"$ref\": \"#/definitions/error\" },\n {\n \"type\": \"array\",\n \"items\": {\n \"oneOf\": [\n { \"$ref\": \"#/definitions/success\" },\n { \"$ref\": \"#/definitions/error\" }\n ]\n }\n }\n ],\n \"definitions\": {\n \"common\": {\n \"required\": [ \"id\", \"jsonrpc\" ],\n \"not\": {\n \"description\": \"cannot have result and error at the same time\",\n \"required\": [ \"result\", \"error\" ]\n },\n \"type\": \"object\",\n \"properties\": {\n \"id\": {\n \"type\": [ \"string\", \"integer\", \"null\" ],\n \"note\": [\n \"spec says a number which should not contain a fractional part\",\n \"We choose integer here, but this is unenforceable with some languages\"\n ]\n },\n \"jsonrpc\": { \"enum\": [ \"2.0\" ] }\n }\n },\n \"success\": {\n \"description\": \"A success. The result member is then required and can be anything.\",\n \"allOf\": [\n { \"$ref\": \"#/definitions/common\" },\n { \"required\": [ \"result\" ] }\n ]\n },\n \"error\": {\n \"allOf\" : [\n { \"$ref\": \"#/definitions/common\" },\n {\n \"required\": [ \"error\" ],\n \"properties\": {\n \"error\": {\n \"type\": \"object\",\n \"required\": [ \"code\", \"message\" ],\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"note\": [ \"unenforceable in some languages\" ]\n },\n \"message\": { \"type\": \"string\" },\n \"data\": {\n \"description\": \"optional, can be anything\"\n }\n }\n }\n }\n }\n ]\n }\n }\n}", | |
"x": 510, | |
"y": 80, | |
"wires": [ | |
[ | |
"56a8e6c7.07c12" | |
] | |
] | |
}, | |
{ | |
"id": "69d3027b.46dd1c", | |
"type": "function", | |
"z": "64220941.ddbd78", | |
"name": "add to queue", | |
"func": "var requests;\n\nif (!flow.get('requests')) {\n requests = {};\n flow.set('requests', requests);\n} else {\n requests = flow.get('requests');\n}\n\nlet hostname = msg.topic.split('/')[1];\nlet id = msg._msgid;\n\nrequests[id] = {};\nrequests[id].hostname = hostname;\nrequests[id].success = false;\n\nreturn msg;", | |
"outputs": 1, | |
"noerr": 0, | |
"x": 550, | |
"y": 220, | |
"wires": [ | |
[ | |
"65fc5e3e.76801" | |
] | |
] | |
}, | |
{ | |
"id": "56a8e6c7.07c12", | |
"type": "function", | |
"z": "64220941.ddbd78", | |
"name": "filter from queue", | |
"func": "let requests = flow.get('requests');\nlet hostname = msg.topic.split('/')[1];\n\nif (requests.hasOwnProperty(msg.payload.id)) {\n if (requests[msg.payload.id].hostname == hostname || requests[msg.payload.id].hostname == '*') {\n requests[msg.payload.id].success = true;\n return msg; \n }\n}\n \n", | |
"outputs": 1, | |
"noerr": 0, | |
"x": 780, | |
"y": 80, | |
"wires": [ | |
[] | |
] | |
}, | |
{ | |
"id": "c77febe8.313ac8", | |
"type": "function", | |
"z": "64220941.ddbd78", | |
"name": "delete from queue", | |
"func": "let requests = flow.get('requests');\nif (requests[msg._msgid].success === false) {\n node.warn(`Request ${msg._msgid} timed out`);\n}\ndelete requests[msg._msgid];", | |
"outputs": 1, | |
"noerr": 0, | |
"x": 750, | |
"y": 160, | |
"wires": [ | |
[] | |
] | |
}, | |
{ | |
"id": "949888e5.7f206", | |
"type": "subflow", | |
"name": "mqtt request old", | |
"info": "", | |
"in": [ | |
{ | |
"x": 80, | |
"y": 280, | |
"wires": [ | |
{ | |
"id": "5f026a95.7f2834" | |
} | |
] | |
} | |
], | |
"out": [ | |
{ | |
"x": 1000, | |
"y": 140, | |
"wires": [ | |
{ | |
"id": "dc34b9f8.a830d8", | |
"port": 0 | |
}, | |
{ | |
"id": "dc34b9f8.a830d8", | |
"port": 1 | |
} | |
] | |
} | |
] | |
}, | |
{ | |
"id": "e94c724.3cba21", | |
"type": "mqtt out", | |
"z": "949888e5.7f206", | |
"name": "", | |
"topic": "", | |
"qos": "", | |
"retain": "", | |
"broker": "efdb112b.a66a7", | |
"x": 770, | |
"y": 280, | |
"wires": [] | |
}, | |
{ | |
"id": "772922bb.2e13fc", | |
"type": "mqtt in", | |
"z": "949888e5.7f206", | |
"name": "", | |
"topic": "project/+/resp", | |
"qos": "2", | |
"broker": "efdb112b.a66a7", | |
"x": 90, | |
"y": 140, | |
"wires": [ | |
[ | |
"dd61e430.6c53b8" | |
] | |
] | |
}, | |
{ | |
"id": "2ea1c55d.77a032", | |
"type": "change", | |
"z": "949888e5.7f206", | |
"name": "", | |
"rules": [ | |
{ | |
"t": "set", | |
"p": "request_id", | |
"pt": "flow", | |
"to": "payload.id", | |
"tot": "msg" | |
}, | |
{ | |
"t": "set", | |
"p": "hostname", | |
"pt": "flow", | |
"to": "$split(topic,'/')[1]", | |
"tot": "jsonata" | |
} | |
], | |
"action": "", | |
"property": "", | |
"from": "", | |
"to": "", | |
"reg": false, | |
"x": 540, | |
"y": 280, | |
"wires": [ | |
[ | |
"e94c724.3cba21" | |
] | |
] | |
}, | |
{ | |
"id": "f55090e7.7754a8", | |
"type": "switch", | |
"z": "949888e5.7f206", | |
"name": "", | |
"property": "payload.id", | |
"propertyType": "msg", | |
"rules": [ | |
{ | |
"t": "eq", | |
"v": "request_id", | |
"vt": "flow" | |
} | |
], | |
"checkall": "true", | |
"outputs": 1, | |
"x": 670, | |
"y": 140, | |
"wires": [ | |
[ | |
"dc34b9f8.a830d8" | |
] | |
] | |
}, | |
{ | |
"id": "dd61e430.6c53b8", | |
"type": "json", | |
"z": "949888e5.7f206", | |
"name": "", | |
"pretty": false, | |
"x": 250, | |
"y": 140, | |
"wires": [ | |
[ | |
"d80c6338.c8d5b8" | |
] | |
] | |
}, | |
{ | |
"id": "dc34b9f8.a830d8", | |
"type": "switch", | |
"z": "949888e5.7f206", | |
"name": "", | |
"property": "hostname", | |
"propertyType": "flow", | |
"rules": [ | |
{ | |
"t": "eq", | |
"v": "$split(topic,'/')[1]", | |
"vt": "jsonata" | |
}, | |
{ | |
"t": "eq", | |
"v": "*", | |
"vt": "str" | |
} | |
], | |
"checkall": "true", | |
"outputs": 2, | |
"x": 810, | |
"y": 140, | |
"wires": [ | |
[], | |
[] | |
] | |
}, | |
{ | |
"id": "8a675871.8b5e6", | |
"type": "delay", | |
"z": "949888e5.7f206", | |
"name": "", | |
"pauseType": "delay", | |
"timeout": "1", | |
"timeoutUnits": "seconds", | |
"rate": "1", | |
"nbRateUnits": "1", | |
"rateUnits": "second", | |
"randomFirst": "1", | |
"randomLast": "5", | |
"randomUnits": "seconds", | |
"drop": false, | |
"x": 520, | |
"y": 220, | |
"wires": [ | |
[ | |
"96a26acd.9e86d8" | |
] | |
] | |
}, | |
{ | |
"id": "96a26acd.9e86d8", | |
"type": "change", | |
"z": "949888e5.7f206", | |
"name": "", | |
"rules": [ | |
{ | |
"t": "delete", | |
"p": "hostname", | |
"pt": "flow" | |
}, | |
{ | |
"t": "delete", | |
"p": "request_id", | |
"pt": "flow" | |
} | |
], | |
"action": "", | |
"property": "", | |
"from": "", | |
"to": "", | |
"reg": false, | |
"x": 700, | |
"y": 220, | |
"wires": [ | |
[] | |
] | |
}, | |
{ | |
"id": "5f026a95.7f2834", | |
"type": "json-schema-validator", | |
"z": "949888e5.7f206", | |
"name": "RPC Schema validation", | |
"func": "{\n \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n \"description\": \"A JSON RPC 2.0 request\",\n \"oneOf\": [\n {\n \"description\": \"An individual request\",\n \"$ref\": \"#/definitions/request\"\n },\n {\n \"description\": \"An array of requests\",\n \"type\": \"array\",\n \"items\": { \"$ref\": \"#/definitions/request\" }\n }\n ],\n \"definitions\": {\n \"request\": {\n \"type\": \"object\",\n \"required\": [ \"jsonrpc\", \"method\" ],\n \"properties\": {\n \"jsonrpc\": { \"enum\": [ \"2.0\" ] },\n \"method\": {\n \"type\": \"string\"\n },\n \"id\": {\n \"type\": [ \"string\", \"number\", \"null\" ],\n \"note\": [\n \"While allowed, null should be avoided: http://www.jsonrpc.org/specification#id1\",\n \"While allowed, a number with a fractional part should be avoided: http://www.jsonrpc.org/specification#id2\"\n ]\n },\n \"params\": {\n \"type\": [ \"array\", \"object\" ]\n }\n }\n }\n }\n}", | |
"x": 250, | |
"y": 280, | |
"wires": [ | |
[ | |
"2ea1c55d.77a032", | |
"8a675871.8b5e6" | |
] | |
] | |
}, | |
{ | |
"id": "d80c6338.c8d5b8", | |
"type": "json-schema-validator", | |
"z": "949888e5.7f206", | |
"name": "RPC Schema answer validation", | |
"func": "{\n \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n \"description\": \"A JSON RPC 2.0 response\",\n \"oneOf\": [\n { \"$ref\": \"#/definitions/success\" },\n { \"$ref\": \"#/definitions/error\" },\n {\n \"type\": \"array\",\n \"items\": {\n \"oneOf\": [\n { \"$ref\": \"#/definitions/success\" },\n { \"$ref\": \"#/definitions/error\" }\n ]\n }\n }\n ],\n \"definitions\": {\n \"common\": {\n \"required\": [ \"id\", \"jsonrpc\" ],\n \"not\": {\n \"description\": \"cannot have result and error at the same time\",\n \"required\": [ \"result\", \"error\" ]\n },\n \"type\": \"object\",\n \"properties\": {\n \"id\": {\n \"type\": [ \"string\", \"integer\", \"null\" ],\n \"note\": [\n \"spec says a number which should not contain a fractional part\",\n \"We choose integer here, but this is unenforceable with some languages\"\n ]\n },\n \"jsonrpc\": { \"enum\": [ \"2.0\" ] }\n }\n },\n \"success\": {\n \"description\": \"A success. The result member is then required and can be anything.\",\n \"allOf\": [\n { \"$ref\": \"#/definitions/common\" },\n { \"required\": [ \"result\" ] }\n ]\n },\n \"error\": {\n \"allOf\" : [\n { \"$ref\": \"#/definitions/common\" },\n {\n \"required\": [ \"error\" ],\n \"properties\": {\n \"error\": {\n \"type\": \"object\",\n \"required\": [ \"code\", \"message\" ],\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"note\": [ \"unenforceable in some languages\" ]\n },\n \"message\": { \"type\": \"string\" },\n \"data\": {\n \"description\": \"optional, can be anything\"\n }\n }\n }\n }\n }\n ]\n }\n }\n}", | |
"x": 470, | |
"y": 140, | |
"wires": [ | |
[ | |
"f55090e7.7754a8" | |
] | |
] | |
}, | |
{ | |
"id": "efdb112b.a66a7", | |
"type": "mqtt-broker", | |
"z": "", | |
"broker": "10.10.10.83", | |
"port": "8883", | |
"tls": "825c44a1.c1b5e8", | |
"clientid": "", | |
"usetls": true, | |
"compatmode": true, | |
"keepalive": "60", | |
"cleansession": true, | |
"willTopic": "", | |
"willQos": "0", | |
"willRetain": "false", | |
"willPayload": "", | |
"birthTopic": "", | |
"birthQos": "0", | |
"birthRetain": "false", | |
"birthPayload": "" | |
}, | |
{ | |
"id": "825c44a1.c1b5e8", | |
"type": "tls-config", | |
"z": "", | |
"name": "", | |
"cert": "", | |
"key": "", | |
"ca": "", | |
"certname": "", | |
"keyname": "", | |
"caname": "", | |
"verifyservercert": false | |
}, | |
{ | |
"id": "57aeaf64.f88e68", | |
"type": "inject", | |
"z": "b4fe3914.d05ee", | |
"name": "subtract host1", | |
"topic": "project/host1/task", | |
"payload": "{\"jsonrpc\":\"2.0\",\"method\":\"subtract\",\"params\":{\"minuend\":42,\"subtrahend\":23},\"id\":3}", | |
"payloadType": "json", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 160, | |
"y": 200, | |
"wires": [ | |
[ | |
"786734c6.401bd4" | |
] | |
] | |
}, | |
{ | |
"id": "3b5ccfa1.269c08", | |
"type": "subflow:949888e5.7f206", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"x": 1000, | |
"y": 540, | |
"wires": [ | |
[] | |
] | |
}, | |
{ | |
"id": "621106a7.d40f98", | |
"type": "mqtt in", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"topic": "project/host1/task", | |
"qos": "2", | |
"broker": "efdb112b.a66a7", | |
"x": 150, | |
"y": 680, | |
"wires": [ | |
[ | |
"4a830754.556858" | |
] | |
] | |
}, | |
{ | |
"id": "7aa86277.658924", | |
"type": "mqtt in", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"topic": "project/host2/task", | |
"qos": "2", | |
"broker": "efdb112b.a66a7", | |
"x": 150, | |
"y": 860, | |
"wires": [ | |
[ | |
"bc8dea4a.792d58" | |
] | |
] | |
}, | |
{ | |
"id": "25b8f026.d69cc8", | |
"type": "debug", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"active": true, | |
"console": "false", | |
"complete": "payload", | |
"x": 771, | |
"y": 200, | |
"wires": [] | |
}, | |
{ | |
"id": "4a830754.556858", | |
"type": "json", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"pretty": false, | |
"x": 330, | |
"y": 680, | |
"wires": [ | |
[ | |
"5888c0e.b68ddc" | |
] | |
] | |
}, | |
{ | |
"id": "75aef309.c5c3d4", | |
"type": "change", | |
"z": "b4fe3914.d05ee", | |
"name": "subtract", | |
"rules": [ | |
{ | |
"t": "set", | |
"p": "payload.result", | |
"pt": "msg", | |
"to": "payload.params.minuend - payload.params.subtrahend", | |
"tot": "jsonata" | |
}, | |
{ | |
"t": "delete", | |
"p": "payload.params", | |
"pt": "msg" | |
}, | |
{ | |
"t": "delete", | |
"p": "payload.method", | |
"pt": "msg" | |
} | |
], | |
"action": "", | |
"property": "", | |
"from": "", | |
"to": "", | |
"reg": false, | |
"x": 640, | |
"y": 660, | |
"wires": [ | |
[ | |
"7d067518.9e414c" | |
] | |
] | |
}, | |
{ | |
"id": "79f92b8d.5fbdd4", | |
"type": "inject", | |
"z": "b4fe3914.d05ee", | |
"name": "subtract host2", | |
"topic": "project/host2/task", | |
"payload": "{\"jsonrpc\":\"2.0\",\"method\":\"subtract\",\"params\":{\"minuend\":100,\"subtrahend\":23},\"id\":3}", | |
"payloadType": "json", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 160, | |
"y": 240, | |
"wires": [ | |
[ | |
"786734c6.401bd4" | |
] | |
] | |
}, | |
{ | |
"id": "bc8dea4a.792d58", | |
"type": "json", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"pretty": false, | |
"x": 330, | |
"y": 860, | |
"wires": [ | |
[ | |
"314203f1.ba5504" | |
] | |
] | |
}, | |
{ | |
"id": "c7db852.0b93578", | |
"type": "change", | |
"z": "b4fe3914.d05ee", | |
"name": "subtract", | |
"rules": [ | |
{ | |
"t": "set", | |
"p": "payload.result", | |
"pt": "msg", | |
"to": "payload.params.minuend - payload.params.subtrahend", | |
"tot": "jsonata" | |
}, | |
{ | |
"t": "delete", | |
"p": "payload.params", | |
"pt": "msg" | |
}, | |
{ | |
"t": "delete", | |
"p": "payload.method", | |
"pt": "msg" | |
} | |
], | |
"action": "", | |
"property": "", | |
"from": "", | |
"to": "", | |
"reg": false, | |
"x": 640, | |
"y": 860, | |
"wires": [ | |
[ | |
"c59fdfd1.656ff" | |
] | |
] | |
}, | |
{ | |
"id": "5888c0e.b68ddc", | |
"type": "switch", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"property": "payload.method", | |
"propertyType": "msg", | |
"rules": [ | |
{ | |
"t": "eq", | |
"v": "subtract", | |
"vt": "str" | |
}, | |
{ | |
"t": "eq", | |
"v": "add", | |
"vt": "str" | |
}, | |
{ | |
"t": "else" | |
} | |
], | |
"checkall": "true", | |
"outputs": 3, | |
"x": 470, | |
"y": 680, | |
"wires": [ | |
[ | |
"75aef309.c5c3d4" | |
], | |
[ | |
"ddc7863e.b5fe4" | |
], | |
[ | |
"b280bdbc.8d2d6" | |
] | |
] | |
}, | |
{ | |
"id": "ddc7863e.b5fe4", | |
"type": "change", | |
"z": "b4fe3914.d05ee", | |
"name": "add", | |
"rules": [ | |
{ | |
"t": "set", | |
"p": "payload.result", | |
"pt": "msg", | |
"to": "payload.params.data1 + payload.params.data2", | |
"tot": "jsonata" | |
}, | |
{ | |
"t": "delete", | |
"p": "payload.params", | |
"pt": "msg" | |
}, | |
{ | |
"t": "delete", | |
"p": "payload.method", | |
"pt": "msg" | |
} | |
], | |
"action": "", | |
"property": "", | |
"from": "", | |
"to": "", | |
"reg": false, | |
"x": 630, | |
"y": 700, | |
"wires": [ | |
[ | |
"7d067518.9e414c" | |
] | |
] | |
}, | |
{ | |
"id": "7320673c.3e1f8", | |
"type": "inject", | |
"z": "b4fe3914.d05ee", | |
"name": "add host1", | |
"topic": "project/host1/task", | |
"payload": "{\"jsonrpc\":\"2.0\",\"method\":\"add\",\"params\":{\"data1\":100,\"data2\":23},\"id\":3}", | |
"payloadType": "json", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 140, | |
"y": 280, | |
"wires": [ | |
[ | |
"786734c6.401bd4" | |
] | |
] | |
}, | |
{ | |
"id": "c6da28e1.ad95c8", | |
"type": "inject", | |
"z": "b4fe3914.d05ee", | |
"name": "multiply host1 (invalid)", | |
"topic": "project/host1/task", | |
"payload": "{\"jsonrpc\":\"2.0\",\"method\":\"multiply\",\"params\":{\"data1\":100,\"data2\":23},\"id\":3}", | |
"payloadType": "json", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 180, | |
"y": 320, | |
"wires": [ | |
[ | |
"786734c6.401bd4" | |
] | |
] | |
}, | |
{ | |
"id": "314203f1.ba5504", | |
"type": "switch", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"property": "payload.method", | |
"propertyType": "msg", | |
"rules": [ | |
{ | |
"t": "eq", | |
"v": "subtract", | |
"vt": "str" | |
}, | |
{ | |
"t": "else" | |
} | |
], | |
"checkall": "true", | |
"outputs": 2, | |
"x": 470, | |
"y": 860, | |
"wires": [ | |
[ | |
"c7db852.0b93578" | |
], | |
[ | |
"94bb9ba4.e265c" | |
] | |
] | |
}, | |
{ | |
"id": "b280bdbc.8d2d6", | |
"type": "change", | |
"z": "b4fe3914.d05ee", | |
"name": "else", | |
"rules": [ | |
{ | |
"t": "set", | |
"p": "payload.error", | |
"pt": "msg", | |
"to": "{\"code\": -32601, \"message\": \"Method not found\"}", | |
"tot": "json" | |
}, | |
{ | |
"t": "delete", | |
"p": "payload.method", | |
"pt": "msg" | |
}, | |
{ | |
"t": "delete", | |
"p": "payload.params", | |
"pt": "msg" | |
} | |
], | |
"action": "", | |
"property": "", | |
"from": "", | |
"to": "", | |
"reg": false, | |
"x": 630, | |
"y": 740, | |
"wires": [ | |
[ | |
"7d067518.9e414c" | |
] | |
] | |
}, | |
{ | |
"id": "94bb9ba4.e265c", | |
"type": "change", | |
"z": "b4fe3914.d05ee", | |
"name": "else", | |
"rules": [ | |
{ | |
"t": "set", | |
"p": "payload.error", | |
"pt": "msg", | |
"to": "{\"code\": -32601, \"message\": \"Method not found\"}", | |
"tot": "json" | |
}, | |
{ | |
"t": "delete", | |
"p": "payload.method", | |
"pt": "msg" | |
}, | |
{ | |
"t": "delete", | |
"p": "payload.params", | |
"pt": "msg" | |
} | |
], | |
"action": "", | |
"property": "", | |
"from": "", | |
"to": "", | |
"reg": false, | |
"x": 630, | |
"y": 900, | |
"wires": [ | |
[ | |
"c59fdfd1.656ff" | |
] | |
] | |
}, | |
{ | |
"id": "ba8c45ad.0388b8", | |
"type": "inject", | |
"z": "b4fe3914.d05ee", | |
"name": "add host2 (invalid)", | |
"topic": "project/host2/task", | |
"payload": "{\"jsonrpc\":\"2.0\",\"method\":\"add\",\"params\":{\"data1\":100,\"data2\":23},\"id\":3}", | |
"payloadType": "json", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 170, | |
"y": 400, | |
"wires": [ | |
[ | |
"786734c6.401bd4" | |
] | |
] | |
}, | |
{ | |
"id": "a0fe9f39.c5e308", | |
"type": "mqtt in", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"topic": "project/*/task", | |
"qos": "2", | |
"broker": "efdb112b.a66a7", | |
"x": 130, | |
"y": 720, | |
"wires": [ | |
[ | |
"4a830754.556858" | |
] | |
] | |
}, | |
{ | |
"id": "138d22f9.072335", | |
"type": "mqtt in", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"topic": "project/*/task", | |
"qos": "2", | |
"broker": "efdb112b.a66a7", | |
"x": 130, | |
"y": 900, | |
"wires": [ | |
[ | |
"bc8dea4a.792d58" | |
] | |
] | |
}, | |
{ | |
"id": "32386efd.f9853a", | |
"type": "inject", | |
"z": "b4fe3914.d05ee", | |
"name": "add *", | |
"topic": "project/*/task", | |
"payload": "{\"jsonrpc\":\"2.0\",\"method\":\"add\",\"params\":{\"data1\":100,\"data2\":23},\"id\":3}", | |
"payloadType": "json", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 130, | |
"y": 440, | |
"wires": [ | |
[ | |
"786734c6.401bd4" | |
] | |
] | |
}, | |
{ | |
"id": "4773faab.095f8c", | |
"type": "inject", | |
"z": "b4fe3914.d05ee", | |
"name": "subtract *", | |
"topic": "project/*/task", | |
"payload": "{\"jsonrpc\":\"2.0\",\"method\":\"subtract\",\"params\":{\"minuend\":42,\"subtrahend\":23},\"id\":3}", | |
"payloadType": "json", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 140, | |
"y": 480, | |
"wires": [ | |
[ | |
"786734c6.401bd4" | |
] | |
] | |
}, | |
{ | |
"id": "e221e78a.6b613", | |
"type": "inject", | |
"z": "b4fe3914.d05ee", | |
"name": "subtract host1 (invalid)", | |
"topic": "project/host1/task", | |
"payload": "", | |
"payloadType": "date", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 180, | |
"y": 160, | |
"wires": [ | |
[ | |
"786734c6.401bd4" | |
] | |
] | |
}, | |
{ | |
"id": "9173c50e.bb41d", | |
"type": "inject", | |
"z": "b4fe3914.d05ee", | |
"name": "multiply host2 (invalid)", | |
"topic": "project/host2/task", | |
"payload": "{\"jsonrpc\":\"2.0\",\"method\":\"multiply\",\"params\":{\"data1\":100,\"data2\":23},\"id\":3}", | |
"payloadType": "json", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 180, | |
"y": 360, | |
"wires": [ | |
[ | |
"786734c6.401bd4" | |
] | |
] | |
}, | |
{ | |
"id": "cb288dc1.92a118", | |
"type": "mqtt out", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"topic": "project/host1/resp", | |
"qos": "", | |
"retain": "", | |
"broker": "efdb112b.a66a7", | |
"x": 1010, | |
"y": 660, | |
"wires": [] | |
}, | |
{ | |
"id": "6d786542.a4c8a4", | |
"type": "mqtt out", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"topic": "project/host2/resp", | |
"qos": "", | |
"retain": "", | |
"broker": "efdb112b.a66a7", | |
"x": 1010, | |
"y": 840, | |
"wires": [] | |
}, | |
{ | |
"id": "5ea506.acf03afc", | |
"type": "comment", | |
"z": "b4fe3914.d05ee", | |
"name": "MQTT Request example with JSON RPC 2.0 validation", | |
"info": "", | |
"x": 260, | |
"y": 40, | |
"wires": [] | |
}, | |
{ | |
"id": "cade28d9.357f2", | |
"type": "comment", | |
"z": "b4fe3914.d05ee", | |
"name": "host1 implements subtract and add", | |
"info": "", | |
"x": 200, | |
"y": 620, | |
"wires": [] | |
}, | |
{ | |
"id": "48b4c64.ded6238", | |
"type": "comment", | |
"z": "b4fe3914.d05ee", | |
"name": "host2 implements subtract", | |
"info": "", | |
"x": 170, | |
"y": 800, | |
"wires": [] | |
}, | |
{ | |
"id": "f2e9b05a.be1158", | |
"type": "comment", | |
"z": "b4fe3914.d05ee", | |
"name": "JSON RPC requests sent to either host1, host2 or all using the * wildcard", | |
"info": "", | |
"x": 320, | |
"y": 120, | |
"wires": [] | |
}, | |
{ | |
"id": "786734c6.401bd4", | |
"type": "change", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"rules": [ | |
{ | |
"t": "set", | |
"p": "payload.id", | |
"pt": "msg", | |
"to": "_msgid", | |
"tot": "msg" | |
} | |
], | |
"action": "", | |
"property": "", | |
"from": "", | |
"to": "", | |
"reg": false, | |
"x": 390, | |
"y": 200, | |
"wires": [ | |
[ | |
"6476b30d.658774" | |
] | |
] | |
}, | |
{ | |
"id": "6476b30d.658774", | |
"type": "subflow:64220941.ddbd78", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"x": 590, | |
"y": 200, | |
"wires": [ | |
[ | |
"25b8f026.d69cc8" | |
] | |
] | |
}, | |
{ | |
"id": "7d067518.9e414c", | |
"type": "delay", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"pauseType": "delay", | |
"timeout": "700", | |
"timeoutUnits": "milliseconds", | |
"rate": "1", | |
"nbRateUnits": "1", | |
"rateUnits": "second", | |
"randomFirst": "1", | |
"randomLast": "5", | |
"randomUnits": "seconds", | |
"drop": false, | |
"x": 810, | |
"y": 660, | |
"wires": [ | |
[ | |
"cb288dc1.92a118" | |
] | |
] | |
}, | |
{ | |
"id": "c59fdfd1.656ff", | |
"type": "delay", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"pauseType": "delay", | |
"timeout": "500", | |
"timeoutUnits": "milliseconds", | |
"rate": "1", | |
"nbRateUnits": "1", | |
"rateUnits": "second", | |
"randomFirst": "1", | |
"randomLast": "5", | |
"randomUnits": "seconds", | |
"drop": false, | |
"x": 810, | |
"y": 860, | |
"wires": [ | |
[ | |
"6d786542.a4c8a4" | |
] | |
] | |
}, | |
{ | |
"id": "1fdde673.c4bb1a", | |
"type": "mqtt in", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"topic": "project/host3/task", | |
"qos": "2", | |
"broker": "efdb112b.a66a7", | |
"x": 150, | |
"y": 1060, | |
"wires": [ | |
[ | |
"98525fbd.e1b0b8" | |
] | |
] | |
}, | |
{ | |
"id": "98525fbd.e1b0b8", | |
"type": "json", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"pretty": false, | |
"x": 330, | |
"y": 1060, | |
"wires": [ | |
[ | |
"ef0339d.174ebc8" | |
] | |
] | |
}, | |
{ | |
"id": "c2c3494c.de3fb", | |
"type": "change", | |
"z": "b4fe3914.d05ee", | |
"name": "subtract", | |
"rules": [ | |
{ | |
"t": "set", | |
"p": "payload.result", | |
"pt": "msg", | |
"to": "payload.params.minuend - payload.params.subtrahend", | |
"tot": "jsonata" | |
}, | |
{ | |
"t": "delete", | |
"p": "payload.params", | |
"pt": "msg" | |
}, | |
{ | |
"t": "delete", | |
"p": "payload.method", | |
"pt": "msg" | |
} | |
], | |
"action": "", | |
"property": "", | |
"from": "", | |
"to": "", | |
"reg": false, | |
"x": 640, | |
"y": 1060, | |
"wires": [ | |
[ | |
"18836bf1.d6f2a4" | |
] | |
] | |
}, | |
{ | |
"id": "ef0339d.174ebc8", | |
"type": "switch", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"property": "payload.method", | |
"propertyType": "msg", | |
"rules": [ | |
{ | |
"t": "eq", | |
"v": "subtract", | |
"vt": "str" | |
}, | |
{ | |
"t": "else" | |
} | |
], | |
"checkall": "true", | |
"outputs": 2, | |
"x": 470, | |
"y": 1060, | |
"wires": [ | |
[ | |
"c2c3494c.de3fb" | |
], | |
[ | |
"a02654aa.07ce28" | |
] | |
] | |
}, | |
{ | |
"id": "a02654aa.07ce28", | |
"type": "change", | |
"z": "b4fe3914.d05ee", | |
"name": "else", | |
"rules": [ | |
{ | |
"t": "set", | |
"p": "payload.error", | |
"pt": "msg", | |
"to": "{\"code\": -32601, \"message\": \"Method not found\"}", | |
"tot": "json" | |
}, | |
{ | |
"t": "delete", | |
"p": "payload.method", | |
"pt": "msg" | |
}, | |
{ | |
"t": "delete", | |
"p": "payload.params", | |
"pt": "msg" | |
} | |
], | |
"action": "", | |
"property": "", | |
"from": "", | |
"to": "", | |
"reg": false, | |
"x": 630, | |
"y": 1100, | |
"wires": [ | |
[ | |
"18836bf1.d6f2a4" | |
] | |
] | |
}, | |
{ | |
"id": "1dd2cf0f.a50c21", | |
"type": "mqtt in", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"topic": "project/*/task", | |
"qos": "2", | |
"broker": "efdb112b.a66a7", | |
"x": 130, | |
"y": 1100, | |
"wires": [ | |
[ | |
"98525fbd.e1b0b8" | |
] | |
] | |
}, | |
{ | |
"id": "1102bb32.4de545", | |
"type": "mqtt out", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"topic": "project/host2/resp", | |
"qos": "", | |
"retain": "", | |
"broker": "efdb112b.a66a7", | |
"x": 1010, | |
"y": 1040, | |
"wires": [] | |
}, | |
{ | |
"id": "1348fa13.1865ae", | |
"type": "comment", | |
"z": "b4fe3914.d05ee", | |
"name": "host3 should timeout", | |
"info": "", | |
"x": 160, | |
"y": 1000, | |
"wires": [] | |
}, | |
{ | |
"id": "18836bf1.d6f2a4", | |
"type": "delay", | |
"z": "b4fe3914.d05ee", | |
"name": "", | |
"pauseType": "delay", | |
"timeout": "1700", | |
"timeoutUnits": "milliseconds", | |
"rate": "1", | |
"nbRateUnits": "1", | |
"rateUnits": "second", | |
"randomFirst": "1", | |
"randomLast": "5", | |
"randomUnits": "seconds", | |
"drop": false, | |
"x": 820, | |
"y": 1040, | |
"wires": [ | |
[ | |
"1102bb32.4de545" | |
] | |
] | |
}, | |
{ | |
"id": "739b4f4b.9053c8", | |
"type": "inject", | |
"z": "b4fe3914.d05ee", | |
"name": "subtract host3 (should timeout)", | |
"topic": "project/host3/task", | |
"payload": "{\"jsonrpc\":\"2.0\",\"method\":\"subtract\",\"params\":{\"minuend\":42,\"subtrahend\":23},\"id\":3}", | |
"payloadType": "json", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 210, | |
"y": 520, | |
"wires": [ | |
[ | |
"786734c6.401bd4" | |
] | |
] | |
}, | |
{ | |
"id": "1a04a0f4.b4b277", | |
"type": "inject", | |
"z": "b4fe3914.d05ee", | |
"name": "subtract host4 (should timeout)", | |
"topic": "project/host4/task", | |
"payload": "{\"jsonrpc\":\"2.0\",\"method\":\"subtract\",\"params\":{\"minuend\":42,\"subtrahend\":23},\"id\":3}", | |
"payloadType": "json", | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"x": 210, | |
"y": 560, | |
"wires": [ | |
[ | |
"786734c6.401bd4" | |
] | |
] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment