我有两个Google Cloud功能FN1和FN2。
我想从FN1开火,而忘记FN2。那不是等待FN2的响应并终止FN1的执行。
这会导致任何资源泄漏吗?我要问的原因是,即使FN1已成功用HTTP 2xx代码终止,当FN2失败并出现非HTTP 2xx响应时,我也确实在FN1的日志中看到错误。
答案 0 :(得分:2)
我想从FN1开火,而忘记FN2。那不是在等待FN2的 响应并终止FN1的执行。
执行此操作的标准方法是使用Cloud Pub/Sub triggered Cloud Function。
在FN1中,您将消息发布到专用的Pub / Sub主题,如下所示,例如:
const pubSubClient = new PubSub();
const topicName = 'mytopic';
const pubSubPayload = { //If needed you can pass a message to FN2
foo: "bar",
}
const dataBuffer = Buffer.from(JSON.stringify(pubSubPayload));
await pubSubClient.topic(topicName).publish(dataBuffer);
//terminate FN1, e.g. return null; or res.send();
然后,按以下方式定义FN2:
exports.fn2 = functions.pubsub.topic('mytopic').onPublish(async (message) => {
const foo = message.json.foo; //Get the value passed to FN2
});