Google Cloud Platform 发布/订阅 - 消息未传递给订阅者

Posted

技术标签:

【中文标题】Google Cloud Platform 发布/订阅 - 消息未传递给订阅者【英文标题】:Google Cloud Platform pub/sub - messages aren't being being delivered to subscriber 【发布时间】:2019-11-06 18:47:55 【问题描述】:

我正在根据 google (https://developers.google.com/gmail/api/guides/push) 提供的指南为 gmail 设置推送通知。我想让我的节点应用程序使用 .watch() 注册一个客户端,然后在指定的端点接收电子邮件,如文档中所述。

我创建了 pub/sub 主题,将 gmail 添加为发布者,添加了订阅者,并在我的节点应用程序中调用了 watch()。 watch() 返回相应的 historyId: xxxx, expiration: yyyy 对象,根据谷歌的文档,这意味着调用成功。

用于在后端接收电子邮件通知的处理程序:

export const receiveGmailEmail: RequestHandler = async (req, res) => 
  log('Received update from google!');
  log(JSON.stringify(req.body, null, 2));
  return res.status(200);

注册:

  const watchRes = await gmailClient.watch();
  log('====> Watch Response <=====');
  log(JSON.stringify(watchRes, null, 2));

显示它正在正确注册的服务器日志: ====> 观看响应

我从未在我的节点应用程序的接收端点收到消息。根据服务器日志,发布消息时我实际上从未收到任何请求。问题似乎是我的消息未送达。我已通过 Stackdriver 监视器确认,当我向电子邮件地址发送电子邮件时,发布/订阅主题正在发布消息,但如果我在 Stackdriver 中查看订阅的详细信息,它会显示越来越多的未发送消息。

对于为什么订阅中的消息未送达有什么想法吗?

【问题讨论】:

您在此步骤中配置的 Pub/Sub 订阅是拉取订阅还是推送订阅? developers.google.com/gmail/api/guides/… 你能在 Stackdriver 中查看 subscription/pull_request_count 和 subscription/push_request_count 指标吗?记录了哪些 response_code?​​span> 嗨劳伦!订阅设置为推送订阅 push_request_count 指标为 1,response_class 为 remote_server_4xx,response_code 为 403(谢谢指出,之前没看到!)。查看谷歌文档,我认为这意味着存在权限问题(cloud.google.com/pubsub/docs/reference/error-codes)。我已验证我已在我的主题中添加了一个服务帐户作为订阅者和 gmail 作为发布者。除了传递要观看的主题名称之外,我还需要做些什么来将服务帐户与我的应用绑定? Pub/Sub 推送到哪个端点?我在问您如何将 receiveGmailEmail 映射到 Pub/Sub 通过 HTTP Post 调用的 HTTP 端点。 @Lauren,对不起,我刚刚意识到我忘记在之前的评论中标记你了! @JohnHanley,节点服务器上的路由映射在另一个文件中完成: const router = Router(); ... const post = router.post.bind(router); ... post('/emails/gmail/receive', receiveGmailEmail);但我认为它甚至没有击中我的服务器,因为我在 AWS 上的服务器日志中看不到任何内容。我希望至少看到一个到达服务器的传入请求,即使我没有处理它的路由 【参考方案1】:

事实证明,这不是 Google 发布/订阅问题。 Amazon Cloudfront 默认阻止 POST 请求,因此我必须编辑缓存行为以启用 POST 请求。 https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesAllowedHTTPMethods

【讨论】:

以上是关于Google Cloud Platform 发布/订阅 - 消息未传递给订阅者的主要内容,如果未能解决你的问题,请参考以下文章

Google Cloud Platform:Cloud Functions 与 App Engine

使用新的 Google Cloud 日志记录 jar 时,日志未显示在 Google Cloud Platform Stackdriver 中

Google Cloud Messaging VS Google Cloud Platform

两个 Firebase 只链接到一个 Google Cloud Platform?

Google Cloud Platform - AI Platform:为啥调用 API 时会得到不同的响应正文?

保存Google Cloud Platform服务帐户凭据的位置