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:
