Note: The push endpoints don't work with the App Engine's local devserver. The push notifications will go to an HTTP URL on the App Engine server even when you run this sample locally. So we recommend you deploy and run the app on App Engine. TODO(tmatsuo): Better implementation for devserver.
-
Go to Google Developers Console and create a new project. This will automatically enable an App Engine application with the same ID as the project.
-
Enable the "Google Cloud Pub/Sub" API under "APIs & auth > APIs."
-
Enable the "Google Cloud Datastore" API under "APIs & auth > APIs."
-
For local development also follow the instructions below.
- Go to "Credentials" and create a new Service Account.
- Select "Generate new JSON key", then download a new JSON file.
- Set the following environment variable:
GOOGLE_APPLICATION_CREDENTIALS: the file path to the downloaded JSON file.
-
Install
composer -
Install the App Engine Python SDK. We recommend you install Cloud SDK rather than just installing App Engine SDK.
-
Install Google API client library for PHP into 'lib' directory by running:
$ composer install
Run the following commands to create your pubsub subscription topic:
$ gcloud alpha pubsub topics create [your-topic-name]
1 topic(s) created successfully
- projects/[your-project-name]/topics/[your-topic-name]We use
php-pubsub-exampleas the topic name, but you can change this by setting thePUBSUB_TOPICenvironment variable (seeapp.yaml)
Then you need to create your subscription to this topic by supplying the endpoint to be notified when the topic is published to:
gcloud alpha pubsub subscriptions create [your-subscription-name] \
--topic [your-topic-name] \
--push-endpoint https://[your-project-name].appspot.com/receive_message \
–-ack-deadline 30
$ gcloud preview app deploy app.yaml --set-default --project YOUR_PROJECT_NAME
Then access the following URL: https://{YOUR_PROJECT_NAME}.appspot.com/
$ dev_appserver.py -A your-project-name .
- See CONTRIBUTING.md
- See LICENSE
