Firebase的Cloud Functions是否可以在项目中使用? [英] Can Cloud Functions for Firebase be used across projects?

查看:63
本文介绍了Firebase的Cloud Functions是否可以在项目中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当将新的发布/订阅消息发送到第三方项目(即跨项目)中的主题/订阅时,我都希望触发发布/订阅功能(使用functions.pubsub/onPublish).

I was hoping to trigger a Pub/Sub function (using functions.pubsub / onPublish) whenever a new Pub/Sub message is sent to a topic/subscription in a third-party project i.e. cross projects.

经过一些研究和实验,我发现,如果主题名称包含/,则TopicBuilder会引发错误,并且默认为"projects/" + process.env.GCLOUD_PROJECT +"/topics/" + topic(

After some research and experimentation I found that TopicBuilder throws an error if the topic name contains a / and it defaults to "projects/" + process.env.GCLOUD_PROJECT + "/topics/" + topic (https://github.com/firebase/firebase-functions/blob/master/src/providers/pubsub.ts).

我还在Stack Overflow中找到一则帖子,内容为"Firebase提供了一个(相对较薄的)Google Cloud Functions包装器"( Cloud Function和Firebase Functions之间有何区别?)

I also found a post in Stack Overflow that says that "Firebase provides a (relatively thin) wrapper around Google Cloud Functions" (What is the difference between Cloud Function and Firebase Functions?)

这使我研究了Google Cloud Functions.尽管我可以在我拥有的项目中创建对第三方项目中某个主题的预订-在IAM中更改权限后-我找不到一种将功能与该主题相关联的方法.我也没有成功地将功能与第三方项目中的主题和订阅相关联.在控制台中,我只看到项目中的主题,使用gcloud失败.

This led me to look into Google Cloud Functions. Whilst I was able to create a subscription in a project I own to a topic in a third-party project - after changing permissions in IAM - I could not find a way associate a function with the topic. Nor was I successful in associating a function with a topic and subscription in a third-party project. In the console I only see the topics in my project and I had no success using gcloud.

任何人在跨项目使用功能方面都取得了成功,如果是的话,您是如何实现的,是否可以提供文档URL?如果无法通过在第三方项目中发送给主题和订阅的消息来触发功能,那么您能想到一种我可以提取第三方Pub/Sub数据的方式吗?

Has anyone had any success in using a function across projects and, if so, how did you achieve this and is there a documentation URL you could provide? If a function can't be triggered by a message to a topic and subscription in a third-party project can you think of a way that I could ingest third-party Pub/Sub data?

由于将发布/订阅费用计入包含该订阅的项目中,因此我希望该订阅位于具有该主题的第三方项目中.

As Pub/Sub fees are billed to the project that contains the subscription I would prefer that the subscription resides in the third-party project with the topic.

谢谢

推荐答案

Google Cloud Functions当前不允许某个函数侦听另一个项目中的资源.对于Cloud Pub/Sub触发器,您可以通过部署HTTP函数并为要触发该跨项目功能的主题添加Pub/Sub推送订阅来解决此问题.

Google Cloud Functions currently does not not allow a function to listen to a resource in another project. For Cloud Pub/Sub triggers specifically you could get around this by deploying an HTTP-function and add a Pub/Sub push subscription to the topic that you want to fire that cross-project function.

这篇关于Firebase的Cloud Functions是否可以在项目中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆