To view the detailed information about a single topic, 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 view a topic


To get the permissions that
you need to view a topic,

ask your administrator to grant you the
[Managed Kafka Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/managedkafka.md.txt#managedkafka.viewer) (`roles/managedkafka.viewer`) IAM role on your project.


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


This predefined role contains

the permissions required to view a topic. To see the exact permissions that are
required, expand the **Required permissions** section:


#### Required permissions

The following permissions are required to view a topic:

- List topics: `managedkafka.topics.list`
- Get topic: `managedkafka.topics.get`


You might also be able to get
these permissions
with [custom roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles.md.txt) or
other [predefined roles](https://docs.cloud.google.com/iam/docs/roles-overview.md.txt#predefined).

## Topic properties in the console

In the console, you can view the following topic properties:

- **Configurations**: This tab provides general configuration details about
  the topic, including the following:

  - **Name**: The unique identifier of the topic within the cluster.

  - **Partitions**: The number of partitions in the topic. Partitions divide
    the topic's data into segments for scalability and parallelism.

  - **Replicas**: The number of copies (replicas) maintained for each
    partition to ensure data redundancy and availability.

  - **Cluster**: The name of the Managed Service for Apache Kafka cluster to which
    the topic belongs.

  - **Region**: The Google Cloud region where the cluster and the topic is
    located.

  - **Non-default topic parameters**: Any topic-level configuration
    overrides that have been set for the topic, different from the
    cluster-wide defaults.

- **Monitoring**: This tab provides visual charts that display key metrics
  related to the topic's activity and performance. These charts include the
  following:

  - **Byte count** : A time-series chart showing the rate at which bytes are
    produced or sent to the topic. This indicates the volume of data
    published to the topic over time. The corresponding metric is
    `managedkafka.googleapis.com/byte_in_count`.

  - **Request count** : A time-series chart representing the rate of requests
    made to the topic. It reflects the overall activity and usage of the
    topic. The related metric is
    `managedkafka.googleapis.com/topic_request_count`.

  - **Log segments by partition** : This chart displays the number of active
    log segments for each partition within the topic. Log segments are the
    physical files on disk where Kafka stores the topic data. The relevant
    metric is `managedkafka.googleapis.com/log_segments`.

- **Consumer groups**: This section lists the consumer groups that are
  subscribed to the topic. A consumer group is a set of consumers
  that work together to read messages from the topic.

## View a topic

### Console

1. In the Google Cloud console, go to the **Clusters** page.


   [Go to Clusters](https://console.cloud.google.com/managedkafka/clusters)

   <br />

   The clusters that you created in a project are listed.
2. 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.
3. To view a specific topic, click the topic name.

   The topic details page is displayed.

### gcloud


1. In the Google Cloud console, activate Cloud Shell.

   [Activate Cloud Shell](https://console.cloud.google.com/?cloudshell=true)


   At the bottom of the Google Cloud console, a
   [Cloud Shell](https://docs.cloud.google.com/shell/docs/how-cloud-shell-works.md.txt)
   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.
2. Run the [`gcloud managed-kafka topics describe`](https://docs.cloud.google.com/sdk/gcloud/reference/managed-kafka/topics/describe)
   command:

   ```bash
   gcloud managed-kafka topics describe TOPIC_ID \
     --cluster=CLUSTER_ID --location=LOCATION_ID
   ```

   This command fetches and displays comprehensive details about the
   specified topic. This information includes its configuration settings,
   such as the number of partitions, replication factor, and any topic-level
   configuration overrides.

   Replace the following:
   - <var translate="no">TOPIC_ID</var>: The ID of the topic.
   - <var translate="no">CLUSTER_ID</var>: The ID of the cluster containing the topic.
   - <var translate="no">LOCATION_ID</var>: The location of the cluster.

The `gcloud managed-kafka topics describe` command displays minimal
information about a topic, such as the partition count and the replication
factor. To get more detailed information, including partition assignments and
the full set of configuration settings, use the `kafka-topics.sh`
command-line tool.

### Kafka CLI


Before running this command, install the Kafka command-line tools on a Compute Engine VM. The
VM must be able to reach a subnet that is connected to your Managed Service for Apache Kafka
cluster. Follow the instructions in [Produce and consume messages with the Kafka command-line tools](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/quickstart.md.txt).

To view details about a topic, run the `kafka-topics.sh --describe` command:

```bash
kafka-topics.sh --describe \
  --bootstrap-server=BOOTSTRAP_ADDRESS \
  --command-config client.properties \
  --topic TOPIC_ID
```

Replace the following:

- <var translate="no">BOOTSTRAP_ADDRESS</var>: The [bootstrap address](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/view-cluster.md.txt#view-bootstrap-address) of the Managed Service for Apache Kafka cluster.
- <var translate="no">TOPIC_ID</var>: The ID of the topic.

This command returns a subset of the topic's properties, including the
following:

- Partition count
- Replication factor
- Partition assignments
- Dynamic configuration (settings that you have explicitly set)
- Static configuration (settings that are applied when the cluster is started)

To view the complete set of configuration settings for a topic, including
settings with default values, run the `kafka-configs.sh --describe` command:

```bash
kafka-configs.sh --describe \
--bootstrap-server=BOOTSTRAP_ADDRESS \
--command-config client.properties \
--entity-type topics \
--entity-name TOPIC_ID \
--all
```

The output is a list of settings as key-value pairs. The `--all` flag returns
all configuration settings. To get a list of only dynamic configuration
settings, omit the `--all` flag.

### REST


Before using any of the request data,
make the following replacements:

- `PROJECT_ID`: your Google Cloud project ID
- `LOCATION`: the location of the cluster
- `CLUSTER_ID`: the ID of the cluster
- `TOPIC_ID`: the ID of the topic


HTTP method and URL:

```
GET https://managedkafka.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/clusters/CLUSTER_ID/topics/TOPIC_ID
```

To send your request, expand one of these options:

#### curl (Linux, macOS, or Cloud Shell)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
curl -X GET \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     "https://managedkafka.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/clusters/CLUSTER_ID/topics/TOPIC_ID"
```

#### PowerShell (Windows)

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method GET `
    -Headers $headers `
    -Uri "https://managedkafka.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/clusters/CLUSTER_ID/topics/TOPIC_ID" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following:

```
{
  "name": "projects/PROJECT_ID/locations/LOCATION/clusters/CLUSTER_ID/topics/TOPIC_ID",
  "partitionCount": PARTITION_COUNT,
  "replicationFactor": REPLICATION_FACTOR
}
```

<br />

### Go


Before trying this sample, follow the Go setup instructions in
[Install the client libraries](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/reference/libraries.md.txt#install). For more information,
see the [Managed Service for Apache Kafka Go API reference documentation](https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/managedkafka/latest/apiv1.md.txt).

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](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment.md.txt).

```go
import (
	"context"
	"fmt"
	"io"

	"cloud.google.com/go/managedkafka/apiv1/managedkafkapb"
	"google.golang.org/api/option"

	managedkafka "cloud.google.com/go/managedkafka/apiv1"
)

func getTopic(w io.Writer, projectID, region, clusterID, topicID string, opts ...option.ClientOption) error {
	// projectID := "my-project-id"
	// region := "us-central1"
	// clusterID := "my-cluster"
	// topicID := "my-topic"
	ctx := context.Background()
	client, err := managedkafka.NewClient(ctx, opts...)
	if err != nil {
		return fmt.Errorf("managedkafka.NewClient got err: %w", err)
	}
	defer client.Close()

	clusterPath := fmt.Sprintf("projects/%s/locations/%s/clusters/%s", projectID, region, clusterID)
	topicPath := fmt.Sprintf("%s/topics/%s", clusterPath, topicID)
	req := &managedkafkapb.GetTopicRequest{
		Name: topicPath,
	}
	topic, err := client.GetTopic(ctx, req)
	if err != nil {
		return fmt.Errorf("client.GetTopic got err: %w", err)
	}
	fmt.Fprintf(w, "Got topic: %#v\n", topic)
	return nil
}
```

<br />

### Java


Before trying this sample, follow the Java setup instructions in
[Install the client libraries](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/reference/libraries.md.txt#install). For more information,
see the [Managed Service for Apache Kafka Java API reference documentation](https://docs.cloud.google.com/java/docs/reference/google-cloud-managedkafka/latest/overview.md.txt).

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](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment.md.txt).

```java
import com.google.api.gax.rpc.ApiException;
import com.google.cloud.managedkafka.v1.ManagedKafkaClient;
import com.google.cloud.managedkafka.v1.Topic;
import com.google.cloud.managedkafka.v1.TopicName;
import java.io.IOException;

public class GetTopic {

  public static void main(String[] args) throws Exception {
    // TODO(developer): Replace these variables before running the example.
    String projectId = "my-project-id";
    String region = "my-region"; // e.g. us-east1
    String clusterId = "my-cluster";
    String topicId = "my-topic";
    getTopic(projectId, region, clusterId, topicId);
  }

  public static void getTopic(String projectId, String region, String clusterId, String topicId)
      throws Exception {
    try (ManagedKafkaClient managedKafkaClient = ManagedKafkaClient.create()) {
      // This operation is being handled synchronously.
      Topic topic =
          managedKafkaClient.getTopic(TopicName.of(projectId, region, clusterId, topicId));
      System.out.println(topic.getAllFields());
    } catch (IOException | ApiException e) {
      System.err.printf("managedKafkaClient.getTopic got err: %s", e.getMessage());
    }
  }
}
```

<br />

### Python


Before trying this sample, follow the Python setup instructions in
[Install the client libraries](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/reference/libraries.md.txt#install). For more information,
see the [Managed Service for Apache Kafka Python API reference documentation](https://docs.cloud.google.com/python/docs/reference/google-cloud-managedkafka/latest.md.txt).

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](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment.md.txt).

```python
from google.api_core.exceptions import NotFound
from google.cloud import managedkafka_v1

# TODO(developer)
# project_id = "my-project-id"
# region = "us-central1"
# cluster_id = "my-cluster"
# topic_id = "my-topic"

client = managedkafka_v1.ManagedKafkaClient()

topic_path = client.topic_path(project_id, region, cluster_id, topic_id)
request = managedkafka_v1.GetTopicRequest(
    name=topic_path,
)

try:
    topic = client.get_topic(request=request)
    print("Got topic:", topic)
except NotFound as e:
    print(f"Failed to get topic {topic_id} with error: {e.message}")
```

<br />

## What's next?

- [Delete a topic](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/delete-topic.md.txt)

- [Edit a topic](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/edit-topic.md.txt)

- [List all consumer groups](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/list-consumer-groups.md.txt)

- [View a consumer group](https://docs.cloud.google.com/managed-service-for-apache-kafka/docs/view-consumer-group.md.txt)

*Apache Kafka® is a registered
trademark of The Apache Software Foundation or its affiliates in the United
States and/or other countries.*