This is a sample AppEngine app demonstrating use of the Cloud Tasks API using App Engine Queues.
App Engine queues push tasks to an App Engine HTTP target. This application can both create and receive Cloud Tasks.
- Set up a Google Cloud Project and enable billing.
- Enable the Cloud Tasks API.
- Download and install the Cloud SDK.
- Download and install Maven.
- Add an AppEngine App to the project
To create a queue using the Cloud SDK, use the following gcloud command:
gcloud alpha tasks queues create-appengine-queue my-appengine-queueIn this example, the queue will be named my-appengine-queue.
To deploy this sample to your AppEngine Project, use the following command:
gcloud config set project $YOUR_PROJECT_ID
mvn appengine:deployYou can open a browser to your your application with:
gcloud app browseYou can also stream the logs for the application with:
gcloud app logs tail -s defaultYou can create a Cloud Task by sending a POST request to the application.
Optionally, you can set up your settings as environment variables:
export PROJECT_ID=<YOUR_PROJECT_ID>
export LOCATION_ID=<YOUR_ZONE>
export QUEUE_ID=<YOUR_QUEUE_NAME>
Next, you can send a POST request to trigger the /create_task
endpoint:
curl -d "project=$PROJECT_ID" \
-d "location=$LOCATION_ID" \
-d "queue=$QUEUE_ID" \
-d "message=Hello World!" \
--request POST https://<YOUR_PROJECT_URL>.appspot.com/create_taskThis endpoint will create a Cloud Task to trigger the
/example_task_handler endpoint, which will be visible the
application's logs:
Received task with payload: Hello World!