12

Pretty sure there's no way to do this but would be great to reach out to see if anyone else has any ideas.

What I'm trying to do is this:

  • I have 2 microservices hosted on Google Cloud Platform as cloud functions
  • My first microservices does stuff and fires a PubSub message with topic [x]
  • I'd like to set my second microservice up as a push subscriber to the topic [x]. I know I can do this by deploying the 2nd cloud function with a subscription trigger but I don't want to do this as there's no decent way to acknowledge/reject the message (see this post: Google Cloud Functions to only Ack Pub/Sub on success).
  • Therefore I've deployed my 2nd function as having a HTTP trigger. I've then tried to configure the push subscription in the GCP console to this endpoint URL. Of course, this isn't working because the https://[cloud-subdomain].cloudfunctions.net/ isn't a verified domain.

I guess it's just not possible to do what I'm trying to and instead need to create my 2nd microservice in app engine or elsewhere where i can verify a domain.

Thanks in advance!

Louzoid
  • 1,503
  • 2
  • 10
  • 9
  • Why can't you handle the retry yourself (with a max retry count) within the Cloud Function by queuing another message before the cloud function terminates as the [answer in the other post](https://stackoverflow.com/a/44052815/380757) suggests. I feel it is a reasonably simple approach to keep your logic within Cloud Functions. – Tuxdude Jul 07 '17 at 23:43
  • Yep could do that. However, I'd much rather rely on PubSub doing this for me to keep the solution as simple as possible. Thanks for the suggestion though. – Louzoid Jul 10 '17 at 10:57

2 Answers2

7

Site Verification using HTML tag method

Not just domain registrar based verification, you can verify your site using any of the methods listed here. I agree most of these will not work with Cloud Functions, but it is possible to get HTML Tag based verification working in matter of minutes with Cloud functions.

You will need to add the given meta attribute in the HTML response just before the body attribute.

Example:

<meta name="google-site-verification" content="VERIFICATION_TAG" />

Also, Google verifies the domain periodically (even after initial success) and hence you will have to continue returning this response as long as you want to have the URL verified.

How long does verification last?

Google periodically checks if your verification is valid in a way appropriate to your verification method (for example, by checking for the presence of an HTML tag on your site). If verification can no longer be confirmed, your permissions on that property will expire after a certain grace period.

Implement retry mechanism within your Cloud function

This is same as the option explained in the other answer you linked, and IMO simpler. Take currentRetryAttempt as one parameter of the request and increment this value every time you queue up a retry request recursively back to the same function when you're timing out. You will need to check currentRetryAttempt against a maxRetriesAllowed value before queuing up a new retry request.

It does not impose any restrictions on the responses from your Cloud function unlike the previous option.

Tuxdude
  • 47,485
  • 15
  • 109
  • 110
  • Good idea! So you'd ask google to verify a sub directory (your function end point) and respond with some HTML including the meta tag. In my use case, the issue would be that I'd prefer to throw a 500 if I didn't have a message in the body. But perhaps you could take a peek at the headers of the incoming request and serve a different response... I'll have a play with this idea when I get a chance next. – Louzoid Jul 14 '17 at 07:14
  • @Louzoid - If you do find any interesting headers of interest in the verification requests, share the information :) – Tuxdude Jul 14 '17 at 15:25
  • I don't understand how this works considering Google is looking for the tag on the homepage (root dir of the http server), and Cloud Functions, as far as I can tell, requires you to deploy to a subdir like us-central1-my-project.cloudfunctions.net/my-function – Michael Dec 10 '19 at 15:50
0

I published a detailed description of how to send messages from a pubsub topic in project A to a cloud function in project B. Including push endpoint configuration, domain verification and a python code example. This can be found in the following stackoverflow post:

Google pubsub into HTTP triggered cloud function?

Cloudkollektiv
  • 11,852
  • 3
  • 44
  • 71