Skip to content

Latest commit

 

History

History
 
 

tasks

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Google Cloud Tasks Samples

This sample demonstrates using the Cloud Tasks client library. These code snippets are not executable, but are a copy-and-pasteable resource for your own code base. For executable code, see the App Engine Quickstart.

See the Cloud Tasks documentation for more info on Creating HTTP Target tasks.

CreateHttpTask.java constructs a task with an HTTP target and pushes it to your queue.

CreateHttpTask.java constructs a task with an HTTP target and OIDC token and pushes it to your queue.

Initial Setup

Creating a queue

To create a queue using the Cloud SDK, use the following gcloud command:

gcloud tasks queues create <QUEUE_NAME>

The location of your queue is the same as your Google Cloud Project. It can be discovered by using the following gcloud command:

gcloud tasks queues describe <QUEUE_NAME>

the location embedded in the "name" value (for instance, if the name is "projects/my-project/locations/us-central1/queues/my-queue", then the location is "us-central1").

Creating Tasks with HTTP Targets

Set an endpoint to your task handler by replacing the variable url with your HTTP target in CreateHttpTask.java.

The sample will create a task and add it to your queue. As the queue processes each task, it will send the task to the specific URL endpoint.

Using HTTP Targets with Authentication Tokens

Set an endpoint to your task handler by replacing the variable url with your HTTP target in CreateHttpTaskWithToken.java.

Your Cloud Tasks service account, ([email protected]), must have the role of: Service Account Token Creator to generate a tokens.

Create or use an existing service account to authenticate the OIDC token.