Elimina una coda

Elimina una coda.

Esempio di codice

Java

Per scoprire come installare e utilizzare la libreria client per Cloud Tasks, consulta librerie client di Cloud Tasks.

Per eseguire l'autenticazione in Cloud Tasks, configura le Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

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

public class DeleteQueue {

  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";
    String queueId = "my-queue";
    deleteQueue(projectId, locationId, queueId);
  }

  // Delete a queue using the Cloud Tasks client.
  public static void deleteQueue(String projectId, String locationId, String queueId)
      throws IOException {

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

      // Construct the fully qualified queue path.
      String queuePath = QueueName.of(projectId, locationId, queueId).toString();

      // Send delete queue request.
      client.deleteQueue(queuePath);

      System.out.println("Queue deleted: " + queueId);
    }
  }
}

Node.js

Per scoprire come installare e utilizzare la libreria client per Cloud Tasks, consulta librerie client di Cloud Tasks.

Per eseguire l'autenticazione in Cloud Tasks, configura le Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

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

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

async function deleteQueue() {
  // Get the fully qualified path to the queue
  const name = client.queuePath(project, location, queue);

  // Send delete queue request.
  await client.deleteQueue({name});
  console.log(`Deleted queue '${queue}'.`);
}
deleteQueue();

Python

Per scoprire come installare e utilizzare la libreria client per Cloud Tasks, consulta librerie client di Cloud Tasks.

Per eseguire l'autenticazione in Cloud Tasks, configura le Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.

from google.cloud import tasks_v2

def delete_queue(project: str, location: str, queue_id: str) -> None:
    """Delete a queue.
    Args:
        project: The project ID where the queue is located.
        location: The location ID where the queue is located.
        queue_id: The ID of the queue to delete.
    """

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

    # Use the client to send a DeleteQueueRequest.
    client.delete_queue(
        tasks_v2.DeleteQueueRequest(name=client.queue_path(project, location, queue_id))
    )

Passaggi successivi

Per cercare e filtrare esempi di codice per altri prodotti Google Cloud, consulta il browser di esempio Google Cloud.