Implementation:Apache Kafka KafkaAdminClient ListTopics
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Administration, Monitoring |
| Last Updated | 2026-02-09 12:00 GMT |
Overview
Concrete tool for listing Kafka topics via the AdminClient API provided by KafkaAdminClient.
Description
The KafkaAdminClient.listTopics method sends a MetadataRequest to any broker and returns a map of topic names to TopicListing objects. Internal topics can be filtered based on the ListTopicsOptions.
Usage
Use via kafka-topics.sh --list or programmatically through the Admin interface.
Code Reference
Source Location
- Repository: Apache Kafka
- File: clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java
- Lines: L2103-2133
Signature
public ListTopicsResult listTopics(final ListTopicsOptions options)
Import
import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.admin.ListTopicsResult;
import org.apache.kafka.clients.admin.ListTopicsOptions;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| options | ListTopicsOptions | No | Options including listInternal flag |
Outputs
| Name | Type | Description |
|---|---|---|
| ListTopicsResult | ListTopicsResult | Contains KafkaFuture<Set<String>> of topic names and KafkaFuture<Map<String, TopicListing>> |
Usage Examples
List Topics via CLI
bin/kafka-topics.sh --bootstrap-server localhost:9092 --list
bin/kafka-topics.sh --bootstrap-server localhost:9092 --list --exclude-internal
List Topics Programmatically
try (Admin admin = Admin.create(props)) {
Set<String> topics = admin.listTopics().names().get();
topics.forEach(System.out::println);
}
Related Pages
Implements Principle
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment