OpenWhisk:如何在Cloudant更改源中包含新/更新的文档

时间:2017-01-25 16:34:19

标签: cloudant openwhisk

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

详细说明:

定义一个只返回参数的动作(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更改Feed创建触发器:

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

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

活动日志条目:

"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活动日志输出仅包含文档元数据,但不包括文档本身:

{

"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"
}

我错过了什么?

1 个答案:

答案 0 :(得分:1)