Openwhisk composer:如何为Redis实例设置参数以使用并行组合

问题描述

我在 Kubernetes 上运行 OpenWhisk,我的 Redis 实例在 pod 中运行。我想使用并行组合器,但在执行 Parallel combinator requires a properly configured redis instance 时总是会出现以下错误 serverless invoke -f conductor

对我来说,我不太清楚我必须在哪里定义对我的 Redis 实例的访问。目前我已经在并行组合的输入参数对象中定义了它,但我不确定这是否正确。你能帮忙吗?提前致谢!

撰写文件“composition.js”:

'use strict';

const composer = require('openwhisk-composer');

module.exports = composer.sequence(
    composer.function(() => ({
        "$composer": {
            "openwhisk": {
                "ignore_certs": true
            },"redis": {
                "uri": "redis://redis.default.svc.cluster.local:6379"
            }
        }
    })),composer.parallel(
        composer.action('fanOut-dev-alpha'),composer.action('fanOut-dev-alpha')
    )
);

函数文件“handler.js”:

'use strict';

function alpha(params) {
  return new Promise((resolve) => {setTimeout(resolve,1000)})
}

module.exports.alpha = alpha;

无服务器文件“composition.js”:

service: fanOut

provider:
  name: openwhisk
  ignore_certs: true

functions:
  conductor:
    handler: composition.conductor.main
    annotations:
      conductor: true
  alpha:
    handler: handler.alpha

plugins:
  - serverless-openwhisk

解决方法

包含 "$composer" 标记的 json 参数应作为调用最外层 composition 动作的输入参数传递。在您的情况下,它应该类似于:

# your input json should be like:
$ cat input.json
> {
  "$composer": {
      "openwhisk": {
          "ignore_certs": true
      },"redis": {
          "uri": "redis://redis.default.svc.cluster.local:6379"
      }
  },"key":"value"
}
# then you can invoke it with this 
$ serverless invoke -f conductor -p input.json
# or if you're using wsk-cli
$ wsk -i action invoke <your composition action> -P input.json