OpenWhisk:如何在 Cloudant 更改提要中包含 new/updated 文档

OpenWhisk: how to include new/updated document in Cloudant change feed

按照 http://heidloff.net/article/how-to-trigger-openwhisk-cloudant 中概述的步骤,触发操作不会接收 JSON 文档作为参数,即使触发器定义包含 includeDocs true.

详情:

定义一个简单的 returns 参数的动作 (displayEvent.js):

function main(params) {
  return {payload:  params};
}

创建操作:

$ wsk action update displayEvent displayEvent.js
ok: updated action displayEvent

绑定 Cloudant 包:

$ wsk package bind /whisk.system/cloudant srcCloudant --param bluemixServiceName cloudant_for_openwhisk --param dbname src --param host *** --param overwrite false --param username *** --param password ***

为 Cloudant 更改提要创建触发器:

$ wsk trigger create newTrackingEvent --feed /ptitzler_org_dev/srcCloudant/changes --param includeDocs true 
ok: invoked /...

(我也试了参数include_docs但是结果是一样的。)

Activity 日志条目:

"2017-01-25T16:12:34.711142625Z stdout: cloudant trigger feed:  { bluemixServiceName: 'cloudant_for_openwhisk',",
"2017-01-25T16:12:34.711173464Z stdout: authKey: '***',",
"2017-01-25T16:12:34.711184757Z stdout: username: '***',",
"2017-01-25T16:12:34.711194489Z stdout: host: '***',",
"2017-01-25T16:12:34.711205213Z stdout: dbname: 'src',",
"2017-01-25T16:12:34.711214336Z stdout: includeDocs: true,",
"2017-01-25T16:12:34.711223392Z stdout: overwrite: false,",
"2017-01-25T16:12:34.711233436Z stdout: package_endpoint: '10.143.15.111:11000',",
"2017-01-25T16:12:34.711242728Z stdout: lifecycleEvent: 'CREATE',",
"2017-01-25T16:12:34.711251853Z stdout: triggerName: '/_/newTrackingEvent',",
"2017-01-25T16:12:34.711261256Z stdout: password: '***' }",
"2017-01-25T16:12:34.810688295Z stdout: cloudant trigger feed: done http request",
"2017-01-25T16:12:34.811401516Z stdout: { id: ':ptitzler_org_dev:newTrackingEvent',",
"2017-01-25T16:12:34.811430393Z stdout: accounturl: 'https://***-bluemix.cloudant.com',",
"2017-01-25T16:12:34.811441235Z stdout: dbname: 'src',",
"2017-01-25T16:12:34.811451032Z stdout: user: '***',",
"2017-01-25T16:12:34.811460676Z stdout: pass: '***',",
"2017-01-25T16:12:34.81147041Z  stdout: host: '***-bluemix.cloudant.com',",
"2017-01-25T16:12:34.811490203Z stdout: protocol: 'https',",
"2017-01-25T16:12:34.811500637Z stdout: apikey: '***',",
"2017-01-25T16:12:34.811518951Z stdout: callback: { action: { name: '/ptitzler_org_dev/newTrackingEvent' } },",
"2017-01-25T16:12:34.811528767Z stdout: maxTriggers: -1,",
"2017-01-25T16:12:34.811537989Z stdout: triggersLeft: -1,",
"2017-01-25T16:12:34.811558803Z stdout: retriesLeft: 10 }"

创建规则:

$ wsk rule create logEvent newTrackingEvent displayEvent
ok: created rule logEvent

在 Cloudant 中创建新文档

{
 "_id": "0689f19a88edd98512a33df24ab084a4",
 "myproperty": 123
}

生成的 displayEvent activity 日志输出仅包含文档元数据,但不包含文档本身:

{

"duration": 64,
"name": "displayEvent",
"subject": "***",
"activationId": "8d81abfb258e4752bbe74d79601c5a7e",
"publish": false,
"annotations": [
    {
        "key": "limits",
        "value": {
            "timeout": 60000,
            "memory": 256,
            "logs": 10
        }
    },
    {
        "key": "path",
        "value": "ptitzler_org_dev/displayEvent"
    }
],
"version": "0.0.4",
"response": {
    "result": {
        "payload": {
            "seq": "10-g1...4",
            "id": "0689f19a88edd98512a33df24ab084a4",
            "changes": [
                {
                    "rev": "1-bf5fdf2758669105decf1fa0c6853626"
                }
            ],
            "dbname": "src"
        }
    },
    "success": true,
    "status": "success"
},
"end": 1485361317416,
"logs": [ ],
"start": 1485361317352,
"namespace": "ptitzler_org_dev"
}

我错过了什么?

不再支持 includeDocs。请看以下内容:https://developer.ibm.com/openwhisk/2016/12/05/cloudant-feed-change-no-longer-support-includedocs/