List queues
Stay organized with collections
Save and categorize content based on your preferences.
Lists queues.
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[],[],null,["# List queues\n\nLists queues.\n\nCode sample\n-----------\n\n### Java\n\n\nTo learn how to install and use the client library for Cloud Tasks, see\n[Cloud Tasks client libraries](/tasks/docs/reference/libraries).\n\n\nTo authenticate to Cloud Tasks, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import com.google.cloud.tasks.v2.https://cloud.google.com/java/docs/reference/google-cloud-tasks/latest/com.google.cloud.tasks.v2.CloudTasksClient.html;\n import com.google.cloud.tasks.v2.https://cloud.google.com/java/docs/reference/google-cloud-tasks/latest/com.google.cloud.tasks.v2.LocationName.html;\n import com.google.cloud.tasks.v2.https://cloud.google.com/java/docs/reference/google-cloud-tasks/latest/com.google.cloud.tasks.v2.Queue.html;\n import java.io.IOException;\n\n public class ListQueues {\n\n public static void main(String[] args) throws IOException {\n // TODO(developer): Replace these variables before running the sample.\n String projectId = \"my-project-id\";\n String locationId = \"us-central1\";\n listQueues(projectId, locationId);\n }\n\n // List queues using the Cloud Tasks client.\n public static void listQueues(String projectId, String locationId) throws IOException {\n\n // Instantiates a client.\n try (https://cloud.google.com/java/docs/reference/google-cloud-tasks/latest/com.google.cloud.tasks.v2.CloudTasksClient.html client = https://cloud.google.com/java/docs/reference/google-cloud-tasks/latest/com.google.cloud.tasks.v2.CloudTasksClient.html.create()) {\n\n // Construct the fully qualified location path.\n String parent = https://cloud.google.com/java/docs/reference/google-cloud-tasks/latest/com.google.cloud.tasks.v2.LocationName.html.of(projectId, locationId).toString();\n\n // Send list queues request.\n https://cloud.google.com/java/docs/reference/google-cloud-tasks/latest/com.google.cloud.tasks.v2.CloudTasksClient.html.https://cloud.google.com/java/docs/reference/google-cloud-tasks/latest/com.google.cloud.tasks.v2.CloudTasksClient.ListQueuesPagedResponse.html response = client.listQueues(parent);\n\n // Iterate over results and print queue names\n int total = 0;\n for (https://cloud.google.com/java/docs/reference/google-cloud-tasks/latest/com.google.cloud.tasks.v2.Queue.html queue : response.iterateAll()) {\n System.out.println(queue.getName());\n total++;\n }\n\n if (total == 0) {\n System.out.println(\"No queues found!\");\n }\n }\n }\n }\n\n### Node.js\n\n\nTo learn how to install and use the client library for Cloud Tasks, see\n[Cloud Tasks client libraries](/tasks/docs/reference/libraries).\n\n\nTo authenticate to Cloud Tasks, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n // Imports the Google Cloud Tasks library.\n const cloudTasks = require('https://cloud.google.com/nodejs/docs/reference/tasks/latest/overview.html');\n\n // Instantiates a client.\n const client = new cloudTasks.https://cloud.google.com/nodejs/docs/reference/tasks/latest/overview.html();\n\n async function listQueues() {\n // Get the fully qualified path to the region\n const parent = client.locationPath(project, location);\n\n // list all fo the queues\n const [queues] = await client.listQueues({parent});\n\n if (queues.length \u003e 0) {\n console.log('Queues:');\n queues.forEach(queue =\u003e {\n console.log(` ${queue.name}`);\n });\n } else {\n console.log('No queues found!');\n }\n }\n listQueues();\n\n### Python\n\n\nTo learn how to install and use the client library for Cloud Tasks, see\n[Cloud Tasks client libraries](/tasks/docs/reference/libraries).\n\n\nTo authenticate to Cloud Tasks, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from typing import List\n\n from google.cloud import tasks_v2\n\n\n def list_queues(project: str, location: str) -\u003e List[str]:\n \"\"\"List all queues\n Args:\n project: The project ID to list queues from.\n location: The location ID to list queues from.\n\n Returns:\n A list of queue names.\n \"\"\"\n\n # Create a client.\n client = tasks_v2.CloudTasksClient()\n\n # Use the client to send a ListQueuesRequest.\n response = client.list_queues(\n tasks_v2.ListQueuesRequest(\n parent=client.common_location_path(project, location)\n )\n )\n\n # Return the results.\n return [queue.name for queue in response]\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=cloud_tasks)."]]