1- # Google Cloud Tasks App Engine Queue Samples
1+ # Google Cloud Tasks Samples
22
3- Sample command-line program for interacting with the Cloud Tasks API
4- using App Engine queues.
5-
6- App Engine queues push tasks to an App Engine HTTP target. This directory
7- contains both the App Engine app to deploy, as well as the snippets to run
8- locally to push tasks to it, which could also be called on App Engine.
3+ This sample demonstrates using the Cloud Tasks client library.
94
105` CreateHTTPTask.java ` constructs a task with an HTTP target and pushes it
116to your queue.
127
13- ` CreateHTTPTask.java ` constructs a task with an HTTP target and OIDC token and pushes it
14- to your queue.
8+ ` CreateHTTPTask.java ` constructs a task with an HTTP target and OIDC token and
9+ pushes it to your queue.
1510
1611## Initial Setup
1712
@@ -27,18 +22,7 @@ to your queue.
2722To create a queue using the Cloud SDK, use the following gcloud command:
2823
2924```
30- gcloud beta tasks queues create-app-engine-queue my-queue
31- ```
32-
33- Note: A newly created queue will route to the default App Engine service and
34- version unless configured to do otherwise.
35-
36- ## Deploying the App Engine app
37- [ Using Maven and the App Engine Plugin] ( https://cloud.google.com/appengine/docs/flexible/java/using-maven )
38- & [ Maven Plugin Goals and Parameters] ( https://cloud.google.com/appengine/docs/flexible/java/maven-reference )
39-
40- ```
41- mvn appengine:deploy
25+ gcloud beta tasks queues create <QUEUE_NAME>
4226```
4327
4428## Run the Sample Using the Command Line
@@ -61,7 +45,7 @@ export QUEUE_ID=my-queue
6145And finally the location ID, which can be discovered with
6246` gcloud beta tasks queues describe $QUEUE_ID ` , with the location embedded in
6347the "name" value (for instance, if the name is
64- "projects/my-project/locations/us-central1/queues/my-appengine- queue", then the
48+ "projects/my-project/locations/us-central1/queues/my-queue", then the
6549location is "us-central1").
6650
6751```
@@ -71,24 +55,32 @@ export LOCATION_ID=<YOUR_ZONE>
7155### Using HTTP Push Queues
7256
7357Set an environment variable for the endpoint to your task handler. This is an
74- example url to send requests to the App Engine task handler :
58+ example url:
7559```
76- export URL=https://${PROJECT_ID}.appspot. com/tasks/create
60+ export URL=https://example. com/taskshandler
7761```
7862
79- Running the sample will create a task and send the task to the specific URL
80- endpoint, with a payload specified :
63+ Running the sample will create a task and add it to your queue. As the queue
64+ processes each task, it will send the task to the specific URL endpoint :
8165
8266```
8367mvn exec:java@HttpTask"
8468```
8569
86- ### Using HTTP Targets with Authentication Headers
70+ ### Using HTTP Targets with Authentication Tokens
71+
72+ Your Cloud Tasks [ service account] [ sa ] ,
73+ (service-<project-number >@gcp-sa-cloudtasks .iam.gserviceaccount.com), must
74+ have the role of: ` Service Account Token Creator ` to generate a tokens.
8775
88- In ` CreateHttpTaskWithToken.java ` , add your service account email in place of
89- ` <SERVICE_ACCOUNT_EMAIL> ` to authenticate the OIDC token.
76+ Create or use an existing [ service account] [ sa ] to replace ` <SERVICE_ACCOUNT_EMAIL> `
77+ in ` CreateHttpTaskWithToken.java ` . This service account will be used to
78+ authenticate the OIDC token.
9079
9180Running the sample with command:
9281```
9382mvn exec:java@WithToken"
9483```
84+
85+
86+ [ sa ] : https://cloud.google.com/iam/docs/service-accounts
0 commit comments