1
- # Google Cloud Tasks App Engine Queue Samples
1
+ # Google Cloud Tasks Samples
2
2
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.
9
4
10
5
` CreateHTTPTask.java ` constructs a task with an HTTP target and pushes it
11
6
to your queue.
12
7
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.
15
10
16
11
## Initial Setup
17
12
@@ -27,18 +22,7 @@ to your queue.
27
22
To create a queue using the Cloud SDK, use the following gcloud command:
28
23
29
24
```
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>
42
26
```
43
27
44
28
## Run the Sample Using the Command Line
@@ -61,7 +45,7 @@ export QUEUE_ID=my-queue
61
45
And finally the location ID, which can be discovered with
62
46
` gcloud beta tasks queues describe $QUEUE_ID ` , with the location embedded in
63
47
the "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
65
49
location is "us-central1").
66
50
67
51
```
@@ -71,24 +55,32 @@ export LOCATION_ID=<YOUR_ZONE>
71
55
### Using HTTP Push Queues
72
56
73
57
Set 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:
75
59
```
76
- export URL=https://${PROJECT_ID}.appspot. com/tasks/create
60
+ export URL=https://example. com/taskshandler
77
61
```
78
62
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 :
81
65
82
66
```
83
67
mvn exec:java@HttpTask"
84
68
```
85
69
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.
87
75
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.
90
79
91
80
Running the sample with command:
92
81
```
93
82
mvn exec:java@WithToken"
94
83
```
84
+
85
+
86
+ [ sa ] : https://cloud.google.com/iam/docs/service-accounts
0 commit comments