Enumerar filas

Organiza tus páginas con colecciones Guarda y categoriza el contenido según tus preferencias.

Enumera las colas.

Muestra de código

Java

Para obtener información sobre cómo instalar y usar la biblioteca cliente de Cloud Tasks, consulta Bibliotecas cliente de Cloud Tasks.

import com.google.cloud.tasks.v2.CloudTasksClient;
import com.google.cloud.tasks.v2.LocationName;
import com.google.cloud.tasks.v2.Queue;
import java.io.IOException;

public class ListQueues {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "my-project-id";
    String locationId = "us-central1";
    listQueues(projectId, locationId);
  }

  // List queues using the Cloud Tasks client.
  public static void listQueues(String projectId, String locationId) throws IOException {

    // Instantiates a client.
    try (CloudTasksClient client = CloudTasksClient.create()) {

      // Construct the fully qualified location path.
      String parent = LocationName.of(projectId, locationId).toString();

      // Send list queues request.
      CloudTasksClient.ListQueuesPagedResponse response = client.listQueues(parent);

      // Iterate over results and print queue names
      int total = 0;
      for (Queue queue : response.iterateAll()) {
        System.out.println(queue.getName());
        total++;
      }

      if (total == 0) {
        System.out.println("No queues found!");
      }
    }
  }
}

Node.js

Para obtener información sobre cómo instalar y usar la biblioteca cliente de Cloud Tasks, consulta Bibliotecas cliente de Cloud Tasks.

// Imports the Google Cloud Tasks library.
const cloudTasks = require('@google-cloud/tasks');

// Instantiates a client.
const client = new cloudTasks.CloudTasksClient();

async function listQueues() {
  // Get the fully qualified path to the region
  const parent = client.locationPath(project, location);

  // list all fo the queues
  const [queues] = await client.listQueues({parent});

  if (queues.length > 0) {
    console.log('Queues:');
    queues.forEach(queue => {
      console.log(`  ${queue.name}`);
    });
  } else {
    console.log('No queues found!');
  }
}
listQueues();

Python

Para obtener información sobre cómo instalar y usar la biblioteca cliente de Cloud Tasks, consulta Bibliotecas cliente de Cloud Tasks.

def list_queues(project, location):
    """List all task queues."""

    from google.cloud import tasks_v2

    # Create a client.
    client = tasks_v2.CloudTasksClient()

    # Construct the fully qualified location path.
    parent = f"projects/{project}/locations/{location}"

    # Use the client to obtain the queues.
    response = client.list_queues(request={"parent": parent})

    # Print the results.
    num_results = 0
    for queue in response:
        num_results = num_results + 1
        print(queue.name)

    if num_results == 0:
        print("No queues found!")

¿Qué sigue?

Para buscar y filtrar muestras de código en otros productos de Google Cloud, consulta el navegador de muestra de Google Cloud.