简体   繁体   中英

Calling Google App Engine endpoint from Google Pub/Sub

I created a Google Pub/Sub push subscription which points to a Google App Engine endpoint, but GAE is not receiving anything.

The messages are being published (I can see it on the Pub/Sub console), but never acknowledged.

The endpoint URL should be correct since I made my GAE endpoint public and tested using Postman.

Does Google Pub/Sub not support calling Google App Engine endpoints? Or I'm I missing something here?

Appreciate it someone could help with this.

For a message to be acknowledged, it means it has to be received by the subscriber. How are you trying to do this? I ask because GAE (at least GAE standard) doesn't support streaming which means you can't have an indefinitely open connection listening for messages from pubsub.

Yes Google Pub/Sub supports calling to Google App Engine endpoints. I referred to this documentation .

As per the document, I used App Engine Flex Environment with Pub/Sub push subscription and I am able to fetch the messages that were published from Pub/Sub to the endpoint.

You can refer to the below mentioned steps :

  • Create one application using App Engine Flex Environment by referring to this document .
  • Deploy the application to GCP .
  • The files needed for application deployment are app.yaml, requirements.txt, main.py and index.html file inside a template folder.
  • Folder structure:
Demo→
app.yaml
requirements.txt
main.py
templates→
    index.html

  • Provide the Pub/Sub topic name and token id ( should be the same as Pub/Sub push endpoint token id ) in the app.yaml file.
env_variables:
    PUBSUB_TOPIC: your-topic
    PUBSUB_VERIFICATION_TOKEN: 1234abcd
  • Run gcloud app deploy on the demo directory.
  • After the application is deployed, you will get an endpoint URL with the format : https://PROJECT_ID.REGION_ID.r.appspot.com
  • Example: https://mydemoproject.uc.r.appspot.com
  • Create a Pub/Sub topic and subscription and make the delivery type as push .
  • We need to provide a push endpoint with the format : https://mydemoproject.uc.r.appspot.com/pubsub/push?token=1234abcd

When an application is deployed in App Engine we can access that application at - https://PROJECT_ID.REGION_ID.r.appspot.com

The messages will be received by any of the instances of your application deployed in App Engine.

SSH into your instances and use the App Engine endpoint URL in the VM.

Output of instance 1:

在此处输入图片说明

Output of instance 2:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM