【问题标题】:The Syntax to call a Google Cloud Function from another Google Cloud Function从另一个 Google Cloud Function 调用 Google Cloud Function 的语法
【发布时间】:2017-12-17 16:43:32
【问题描述】:

我想使用 HTTP 触发器创建一个 Google Cloud 函数,该函数调用另一个函数(例如:changeString)。我知道我可以在 index.js 中包含函数 changeString。但是,我想重用 changeString 以便其他 Google Cloud Functions 可以调用它。

exports.helloWorld = function helloWorld(req, res) {
var result = changeString(req.body.string);
res.send(result);
};

我知道有一个similar question,但它并没有解决我的问题。

【问题讨论】:

  • 基本上,我只是想知道从 Google Cloud Function 中的另一个函数调用函数的语法。

标签: node.js function google-cloud-platform google-cloud-functions


【解决方案1】:

正如@user3158158 所指出的,您可以将消息发布到 Pub/Sub 服务。此处突出显示:https://cloud.google.com/functions/docs/calling/pubsub#publishing_a_message_from_within_a_function

我在上面的链接中显示了示例语法,我今天需要做同样的事情。

【讨论】:

  • 请在此处自己写下答案的相关部分,因为链接可能会随着时间而改变。
【解决方案2】:

我自己也想知道这个问题,我认为答案是您不要调用该函数。相反,您应该从 HTTP 云函数向 PubSub 服务发送有效负载。辅助 Cloud Function 订阅 PubSub 主题并使用有效负载(Base64 编码)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-13
    • 2020-12-17
    • 1970-01-01
    • 2020-01-23
    • 1970-01-01
    • 2019-02-14
    • 2020-05-20
    相关资源
    最近更新 更多