Cloud Pub/Sub: HTTP URL is not registered even after domain is registered

隐身守侯 提交于 2021-02-08 15:14:43

问题


I have a Google Pub/Sub project and created a topic and a simple subscription.

However, when specifying a URL for push, I keep getting the error below. I have completed the site verification process and registered the domain in APIs & services as described in https://cloud.google.com/pubsub/docs/push#other-endpoints:

ERROR: Failed to create subscription [projects/<project-id>/subscriptions/my-sub-2]: The supplied HTTP URL is not registered in the subscription's parent project (url="https://us-central1-<project-id>.cloudfunctions.net/xxxx", project_id="<project id number>").
ERROR: (gcloud.pubsub.subscriptions.create) Failed to create the following: [my-sub-2].

Please help !!


回答1:


I walked into this issue numerous times, it is indeed really annoying. It is all about registering the ownership of the http endpoint. This way Google can verify that you are the owner of the supplied endpoint. Information on how to register the endpoint can be found here under domain ownership validation. I included this in my function so Google can verify the registration:

if request.method == 'GET':
    return '''
        <html>
            <head>
                <meta name="google-site-verification" content="{token}" />
            </head>
            <body>
            </body>
        </html>
    '''.format(token=config.SITE_VERIFICATION_CODE)



回答2:


Cloud functions can be set up to explicitly subscribe to a Cloud Pub/Sub topic as described here by setting the --trigger-topic command line parameter, which will not require explicit domain verification.




回答3:


I was having this exact issue, but with app engine. Following this guide I was hitting the same error when creating the subscription like so:

gcloud pubsub subscriptions create <subscription_name> \
                --topic <topic_name> \
                --push-endpoint \
                    https://<PROJECT_ID>.appspot.com/_ah/push-handlers/receive_messages/token=<TOKEN> \
                --ack-deadline 30

After some experimentation and reading of some of the notes listed above (this one from Iñigo was especially useful), I realized that it wasn't that my URL was wrong, but that I didn't include the various project parameters in both the subscription and the topic.

This version worked for me:

gcloud pubsub subscriptions create projects/<PROJECT_ID>/subscriptions/<subscription_name> \
            --topic projects/<PROJECT_ID>/topics/<topic_name> \
            --push-endpoint \
                https://<PROJECT_ID>.appspot.com/_ah/push-handlers/receive_messages/token=<TOKEN> \
            --ack-deadline 30


来源:https://stackoverflow.com/questions/51413501/cloud-pub-sub-http-url-is-not-registered-even-after-domain-is-registered

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!