Search code examples
node.jsemailgoogle-cloud-platformpublish-subscribegoogle-cloud-pubsub

Google Cloud Platform pub/sub - messages aren't being being delivered to subscriber


I am setting up push notifications for gmail based on the guide provided by google (https://developers.google.com/gmail/api/guides/push). I want to have my node app register a client with .watch(), and then receive emails at a specified endpoint, as described in the documentation.

I have created the pub/sub topic, added gmail as a publisher, added a subscriber, and called watch() in my node app. watch() returns the appropriate { historyId: xxxx, expiration: yyyy } object which, according to google's documentation, means the call succeeded.

handler for receiving email notification on backend:

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

Registering:

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

Server log that shows it is registering properly: ====> Watch Response <===== { "historyId": "6560", "expiration": "1562025255689" }

I never receive messages at the receive endpoint on my node app. According to the server logs, I never actually receive any request when a message is published. The problem appears to be that my messages are undelivered. I have confirmed through the Stackdriver monitor that the pub/sub topic is publishing messages when I send an email to the email address, but if I view the details of the subscription in Stackdriver, it shows an increasing number of undelivered messages.

Any thoughts on why messages in a subscription are sitting around undelivered?


Solution

  • It turns out this wasn't a Google pub/sub issue. Amazon Cloudfront blocks POST requests by default, so I had to edit the caching behavior to enable POST requests. https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesAllowedHTTPMethods