如何使用node-red-node-cf-cloudant从插入​​/更新中获取结果

时间:2016-02-28 07:51:51

标签: ibm-cloud cloudant node-red

我正在使用IBM Bluemix IOT Foundation中提供的Node-red。它附带了node-red-node-cf-cloudant软件包,可以轻松处理Cloudant数据库操作。 Cloudant out节点运行良好。我的边界是 Cloudant out节点没有输出,如果插入/更新操作成功,它可以告诉流程。现在我只能假设它总是成功的。有人和我一样有问题吗?你的解决方案是什么?感谢。

2 个答案:

答案 0 :(得分:0)

我认为,哲学是有一个Catch节点的概念可以添加到流中。有关标记为input的节点,请参阅catch类别。阅读此节点的文档,它指出如果同一选项卡/页面/工作流上的任何节点抛出错误,它将被触发。我假设如果Cloudant out节点正确实现,那么如果它失败,它将抛出一些Node-RED格式的错误,导致Catch节点被触发,这样你就可以获得控制来执行任何错误处理,记录或其他可能适用的补救工作。

我猜测跟踪创建的Node-RED Github问题以及可以在其中阅读更多关于该功能的问题可以在这里找到:

https://github.com/node-red/node-red/issues/560

答案 1 :(得分:0)

我有一个答案,虽然它不是一个非常有用的答案。

    [
  {
    "id": "a477543c.5b88a8",
    "type": "debug",
    "z": "7ac871fa.85379",
    "name": "",
    "active": true,
    "console": "false",
    "complete": "false",
    "x": 293,
    "y": 147,
    "wires": []
  },
  {
    "id": "8c8b0763.7374f8",
    "type": "cloudant out",
    "z": "7ac871fa.85379",
    "service": "your_service",
    "cloudant": "",
    "name": "Save Data",
    "database": "your_db",
    "payonly": true,
    "operation": "insert",
    "x": 292,
    "y": 58,
    "wires": []
  },
  {
    "id": "66f48698.990b78",
    "type": "template",
    "z": "7ac871fa.85379",
    "name": "",
    "field": "payload",
    "fieldType": "msg",
    "format": "json",
    "template": "{\"response\": \"success\"}",
    "x": 669,
    "y": 112,
    "wires": [
      [
        "9fc752f6.6038b"
      ]
    ]
  },
  {
    "id": "9a2f1021.65d0f",
    "type": "catch",
    "z": "7ac871fa.85379",
    "name": "Catch error from Save Data",
    "scope": [
      "8c8b0763.7374f8"
    ],
    "x": 130,
    "y": 207,
    "wires": [
      [
        "41c37106.be3c9",
        "35676738.ca9898",
        "9e4a94f4.61b568"
      ]
    ]
  },
  {
    "id": "41c37106.be3c9",
    "type": "debug",
    "z": "7ac871fa.85379",
    "name": "",
    "active": true,
    "console": "true",
    "complete": "true",
    "x": 316,
    "y": 249,
    "wires": []
  },
  {
    "id": "35676738.ca9898",
    "type": "change",
    "z": "7ac871fa.85379",
    "name": "",
    "rules": [
      {
        "t": "set",
        "p": "error",
        "pt": "flow",
        "to": "error",
        "tot": "msg"
      }
    ],
    "action": "",
    "property": "",
    "from": "",
    "to": "",
    "reg": false,
    "x": 330,
    "y": 207,
    "wires": [
      [
        "6c19d8c0.93e628"
      ]
    ]
  },
  {
    "id": "972775b7.68d888",
    "type": "delay",
    "z": "7ac871fa.85379",
    "name": "",
    "pauseType": "delay",
    "timeout": "3",
    "timeoutUnits": "seconds",
    "rate": "1",
    "rateUnits": "second",
    "randomFirst": "1",
    "randomLast": "5",
    "randomUnits": "seconds",
    "drop": false,
    "x": 286,
    "y": 106,
    "wires": [
      [
        "dd0eb63d.22f148"
      ]
    ]
  },
  {
    "id": "dd0eb63d.22f148",
    "type": "switch",
    "z": "7ac871fa.85379",
    "name": "Check flow.error",
    "property": "error",
    "propertyType": "flow",
    "rules": [
      {
        "t": "nnull"
      },
      {
        "t": "else"
      }
    ],
    "checkall": "true",
    "outputs": 2,
    "x": 467,
    "y": 106,
    "wires": [
      [
        "54a9c22f.ab563c"
      ],
      [
        "66f48698.990b78"
      ]
    ]
  },
  {
    "id": "a26776ff.5d9888",
    "type": "template",
    "z": "7ac871fa.85379",
    "name": "",
    "field": "payload",
    "fieldType": "msg",
    "format": "json",
    "template": "{\"response\": {{{payload}}}}\n",
    "x": 975,
    "y": 55,
    "wires": [
      [
        "9fc752f6.6038b"
      ]
    ]
  },
  {
    "id": "54a9c22f.ab563c",
    "type": "change",
    "z": "7ac871fa.85379",
    "name": "",
    "rules": [
      {
        "t": "set",
        "p": "payload",
        "pt": "msg",
        "to": "error",
        "tot": "flow"
      },
      {
        "t": "delete",
        "p": "error",
        "pt": "flow"
      }
    ],
    "action": "",
    "property": "",
    "from": "",
    "to": "",
    "reg": false,
    "x": 687,
    "y": 55,
    "wires": [
      [
        "837ec67c.7c8138"
      ]
    ]
  },
  {
    "id": "6c19d8c0.93e628",
    "type": "debug",
    "z": "7ac871fa.85379",
    "name": "",
    "active": true,
    "console": "false",
    "complete": "false",
    "x": 505,
    "y": 207,
    "wires": []
  },
  {
    "id": "433fc13d.bcc04",
    "type": "inject",
    "z": "7ac871fa.85379",
    "name": "",
    "topic": "",
    "payload": "{\"_id\":\"0fc076a605741fdffa1580897e1c54a0\",\"message\":\"testing\"}",
    "payloadType": "json",
    "repeat": "",
    "crontab": "",
    "once": false,
    "x": 120,
    "y": 57,
    "wires": [
      [
        "8c8b0763.7374f8",
        "972775b7.68d888",
        "a477543c.5b88a8"
      ]
    ]
  },
  {
    "id": "9fc752f6.6038b",
    "type": "debug",
    "z": "7ac871fa.85379",
    "name": "",
    "active": true,
    "console": "false",
    "complete": "false",
    "x": 1119,
    "y": 108,
    "wires": []
  },
  {
    "id": "9e4a94f4.61b568",
    "type": "debug",
    "z": "7ac871fa.85379",
    "name": "",
    "active": true,
    "console": "false",
    "complete": "error",
    "x": 330,
    "y": 297,
    "wires": []
  },
  {
    "id": "837ec67c.7c8138",
    "type": "json",
    "z": "7ac871fa.85379",
    "name": "",
    "x": 843,
    "y": 55,
    "wires": [
      [
        "a26776ff.5d9888"
      ]
    ]
  }
]

检查此代码。我可以使用catch节点捕获从Cloudant输出节点抛出的任何错误,并将其设置为流上下文对象。因此,原始路径可以在短暂延迟之后检查上下文中是否存在错误对象。如果在上下文中找不到错误,则假定更新成功。

但是,这不是一个有用的解决方案。在同一个Node-red实例中收到多个请求时,会出现并发问题。并且错误对象中没有会话标识符。我无法将错误消息与导致错误的消息相关联。希望有人能找到改进此解决方案的方法。