LocalCloud Cloud Tasks Local Emulator
Get started
local.cloud / agents
Read this page as Markdown ↗
local.cloud — Cloud Tasks Local Emulator .md Open tab

Cloud Tasks

Cloud Tasks queues work for later delivery to a handler. Rate limits, retries, and scheduling help control how background requests reach application workers.

When to use Cloud Tasks

Typical uses

Use when a known handler should process queued work with controlled dispatch rates, scheduled delivery, and per-task retry behavior.

Examples

  • Deferred HTTP work
  • Rate-limited background processing

Explore another service

View all

Example usage

Service ID: cloudtasks. Starts by default. Use an already running LocalCloud runtime for the examples below.

Export the local project and mapped endpoints in your client process, then use the client settings below. First-time setup

# Export GOOGLE_CLOUD_PROJECT and CLOUD_TASKS_EMULATOR_HOST
eval "$(localcloud env)"

Java

List local task queues

List the queues that hold deferred work; Cloud Tasks controls how requests reach your background handlers.

Use the Cloud Tasks SDK over the local gRPC endpoint with a plaintext channel and no credentials. Requires JDK 17+ and Maven.

Discovery check · reads existing local state.

SDK dependencies

Run in a new example directory

cat > pom.xml <<'XML'
<project xmlns="http://maven.apache.org/POM/4.0.0">
  <modelVersion>4.0.0</modelVersion>
  <groupId>example</groupId><artifactId>local-example</artifactId><version>1</version>
  <dependencies><dependency>
    <groupId>com.google.cloud</groupId><artifactId>google-cloud-tasks</artifactId><version>2.99.0</version>
  </dependency></dependencies>
</project>
XML
mvn -q dependency:build-classpath -Dmdep.outputFile=classpath.txt

Save as Hello.java

import com.google.api.gax.core.NoCredentialsProvider;
import com.google.api.gax.grpc.GrpcTransportChannel;
import com.google.api.gax.rpc.FixedTransportChannelProvider;
import com.google.cloud.tasks.v2.*;
import io.grpc.ManagedChannelBuilder;
import java.util.Objects;

public class Hello {
  public static void main(String[] args) throws Exception {
    var host = Objects.requireNonNull(System.getenv("CLOUD_TASKS_EMULATOR_HOST"));
    var project = Objects.requireNonNull(System.getenv("GOOGLE_CLOUD_PROJECT"));
    var channel = ManagedChannelBuilder.forTarget(host).usePlaintext().build();
    var settings = CloudTasksSettings.newBuilder()
        .setTransportChannelProvider(FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)))
        .setCredentialsProvider(NoCredentialsProvider.create()).build();
    try (var client = CloudTasksClient.create(settings)) {
      for (var queue : client.listQueues("projects/" + project + "/locations/us-central1").iterateAll()) {
        System.out.println(queue.getName());
      }
    } finally {
      channel.shutdownNow();
    }
  }
}

Run the example

java --class-path "$(cat classpath.txt)" Hello.java

Verify the result

The request succeeds. An empty list or no printed rows is valid before matching resources exist. Continue with the documented workflows for a resource test.

Verify a resource workflow by creating isolated state, performing the operation, and reading the result back. Run cleanup even after a failure; delete only test-owned resources.

Connection failed? Check localcloud status --verbose, enabled services, and client exports. Stop accidental Google Cloud calls; correct local routing before retrying.

Documented workflows

  • Queue lifecycle, pause/resume, purge, and HTTP target overrides

    Create a queue, change dispatch settings, and configure HTTP target URI, method, or header overrides. Check delivered requests, then pause, resume, or purge the queue for the next test run.

  • Task CRUD, BufferTask, and manual/automatic HTTP dispatch

    Create an HTTP task or POST a raw body through BufferTask on a queue with an HTTP target host. Trigger dispatch and assert the received body, delivery headers, and observed response.

  • Rate/concurrency limits, deadlines, retries, and attempt history

    Make the handler fail or exceed a deadline, then inspect attempt history and retry timing. Test rate and concurrency settings with enough tasks to observe their effect.

  • HTTP delivery with locally issued OAuth/OIDC credentials

    Set a task OAuth or OIDC credential and have the receiver verify the local token. Exercise queue-level credential overrides separately from the task-level configuration.

Service boundaries

  • No App Engine dispatch or logging sampling; queue target overrides need exact-image validation
  • Authenticated receivers must trust the local issuer/JWKS
  • Restart can redeliver; pause, purge, and delete cannot cancel in-flight requests. Inspect attempts before replaying
Agent testing

Use Cloud Tasks with an AI agent

Before the agent changes application logic, have it create local Cloud Tasks state, read it back with the project SDK, and note which feature the check covered. That first local call catches accidental production routing and needs no GCP account, service-account key, or billing project.

Configure this repo

Set up this repository to use LocalCloud for local GCP development. First read https://local.cloud/ai/agents.md, then inspect this repo, identify the GCP services and SDK language, configure emulator environment variables, and run the narrowest integration test against localhost. Do not use real GCP credentials or production endpoints.

Production endpoints, auth, IAM, quotas, regional behavior, and final release validation still need the target Google Cloud project.

Agent resources has more prompts and the AGENTS.md template.

Related guides

Desktop view