执行http PUSH到云功能的Google Pubsub订阅者(在同一项目或其他项目中)

时间:2018-04-06 16:07:52

标签: google-cloud-platform google-cloud-functions

是否可以在一个项目中设置pubsub主题/订阅者,该项目在另一个Google项目的同一个OR中对一个云功能进行http PUSH?我知道有PubSub触发器但是当pubsub主题在另一个谷歌项目中时这些不起作用。很奇怪,如果用户PUSH可以做到这一点。

错误如果我尝试创建它,我会得到thiis pubsub错误INVALID_ARGUMENT。我不确定这是不是因为我需要注册端点(https://cloud.google.com/pubsub/docs/push#other-endpoints)。然而,这感觉不对,因为当我创建一个函数时,URL会自动提供给我,我可以通过Postman点击它。

我确实找到了此链接(GCP - Verify ownership of a cloud function https endpoint for a PubSub push)并认为它与网址验证有关..只是想要确认:)

思考?我在某处遗漏了一些文件吗?

编辑:我认为它与网址验证以及使用../_ah/push-handlers/..路径有关。当我注册一个PubSub触发器时,该函数的传递类型仍然是PUSH,但它是一个带有更多路径的编码网址:https://{hash}-dot-{hash}.appspot.com/_ah/push-handlers/pubsub/projects/{project-id}/topics/prototype-contact-created?pubsub_trigger=true

1 个答案:

答案 0 :(得分:4)

这是我在这里给出的解决方案:https://github.com/googleapis/nodejs-pubsub/issues/118

  

您需要通过Google云端控制台API & ServicesCredentials,然后Domain Verification标签来验证此网址。添加网址   您的云功能。你需要为每一个做到这一点   之一。

     

然后,确保在Search Console中选择META TAG   验证方法,以及对GET次请求的响应。

if (req.method === 'GET') {
      // mine is in a settings file but you can hardcode yours for testing purposes
      return res.send(`<html><head><meta name="google-site-verification" content="${settings.google.siteVerificationCode}" /></head><body></body></html>`)
}