To list your topics in a cluster, you can use the Google Cloud console, the Google Cloud CLI, the client library, the Managed Kafka API, or the open source Apache Kafka APIs.
Required roles and permissions to list your topics
To get the permissions that you need to list your topics,
ask your administrator to grant you the
Managed Kafka Viewer (roles/managedkafka.viewer
) IAM role on your project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the permissions required to list your topics. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to list your topics:
-
List topics:
managedkafka.topics.list
-
Get topic:
managedkafka.topics.get
You might also be able to get these permissions with custom roles or other predefined roles.
For more information about the Managed Kafka Viewer (roles/managedkafka.viewer
) IAM role,
see Managed Service for Apache Kafka predefined roles.
List your topics
Console
In the Google Cloud console, go to the Clusters page.
The clusters you created in a project are listed.
- Click the cluster for which you want to see the topics.
The cluster details page is displayed. In the cluster details page, for the Resources tab, the topics are listed.
gcloud
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
Run the
gcloud managed-kafka topics list
command:gcloud managed-kafka topics list CLUSTER_ID \ --location=LOCATION_ID \ --limit=LIMIT
This command retrieves a list of all topics present within the specified Managed Service for Apache Kafka cluster. You can use optional flags to filter, limit, and sort the output.
Replace the following:
CLUSTER_ID: The name of the cluster whose topics you want to list.
LOCATION_ID: The location of the cluster.
LIMIT: (Optional) The maximum number of topics to list.
Go
Before trying this sample, follow the Go setup instructions in Install the client libraries. For more information, see the Managed Service for Apache Kafka Go API reference documentation.
To authenticate to Managed Service for Apache Kafka, set up Application Default Credentials(ADC). For more information, see Set up ADC for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in Install the client libraries. For more information, see the Managed Service for Apache Kafka Java API reference documentation.
To authenticate to Managed Service for Apache Kafka, set up Application Default Credentials. For more information, see Set up ADC for a local development environment.
Python
Before trying this sample, follow the Python setup instructions in Install the client libraries. For more information, see the Managed Service for Apache Kafka Python API reference documentation.
To authenticate to Managed Service for Apache Kafka, set up Application Default Credentials. For more information, see Set up ADC for a local development environment.