Répertorier les files d'attente

Répertorie les files d'attente.

Exemple de code

Java

Pour savoir comment installer et utiliser la bibliothèque cliente pour Cloud Tasks, consultez la page Bibliothèques clientes Cloud Tasks.

Pour vous authentifier auprès de Cloud Tasks, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

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

Pour savoir comment installer et utiliser la bibliothèque cliente pour Cloud Tasks, consultez la page Bibliothèques clientes Cloud Tasks.

Pour vous authentifier auprès de Cloud Tasks, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

// 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

Pour savoir comment installer et utiliser la bibliothèque cliente pour Cloud Tasks, consultez la page Bibliothèques clientes Cloud Tasks.

Pour vous authentifier auprès de Cloud Tasks, configurez les Identifiants par défaut de l'application. Pour en savoir plus, consultez Configurer l'authentification pour un environnement de développement local.

from typing import List

from google.cloud import tasks_v2

def list_queues(project: str, location: str) -> List[str]:
    """List all queues
    Args:
        project: The project ID to list queues from.
        location: The location ID to list queues from.

    Returns:
        A list of queue names.
    """

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

    # Use the client to send a ListQueuesRequest.
    response = client.list_queues(
        tasks_v2.ListQueuesRequest(
            parent=client.common_location_path(project, location)
        )
    )

    # Return the results.
    return [queue.name for queue in response]

Étapes suivantes

Pour rechercher et filtrer des exemples de code pour d'autres produits Google Cloud, consultez l'exemple de navigateur Google Cloud.