Implementation:Apache Kafka KafkaAdminClient DeleteTopics
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Administration, Data_Management |
| Last Updated | 2026-02-09 12:00 GMT |
Overview
Concrete tool for deleting Kafka topics via the AdminClient API provided by KafkaAdminClient.
Description
The KafkaAdminClient.deleteTopics method sends a DeleteTopicsRequest to the Kafka controller. It supports deletion by topic name or topic ID. The method returns futures that complete when the controller acknowledges the deletion.
Usage
Use via kafka-topics.sh --delete 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: L1897-2100
Signature
public DeleteTopicsResult deleteTopics(
final TopicCollection topics,
final DeleteTopicsOptions options
)
Import
import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.admin.DeleteTopicsResult;
import org.apache.kafka.common.TopicCollection;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| topics | TopicCollection | Yes | TopicNameCollection or TopicIdCollection to delete |
| options | DeleteTopicsOptions | No | Options including retryOnQuotaViolation |
Outputs
| Name | Type | Description |
|---|---|---|
| DeleteTopicsResult | DeleteTopicsResult | Contains KafkaFuture<Void> per topic; completes when deletion is acknowledged |
Usage Examples
Delete Topic via CLI
bin/kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic my-topic
bin/kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic my-topic --if-exists
Delete Topic Programmatically
try (Admin admin = Admin.create(props)) {
admin.deleteTopics(
TopicCollection.ofTopicNames(Set.of("my-topic"))
).all().get();
}
Related Pages
Implements Principle
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment