Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Apache Kafka TopicCommand Execute

From Leeroopedia


Knowledge Sources
Domains Administration, CLI_Tools
Last Updated 2026-02-09 12:00 GMT

Overview

Concrete tool for bootstrapping topic management operations via CLI provided by TopicCommand.

Description

The TopicCommand class is the entry point for kafka-topics.sh. The execute method parses arguments into TopicCommandOptions, creates a TopicService backed by Admin.create(), routes to the appropriate operation, and ensures the Admin client is closed in a finally block.

Usage

Invoked via kafka-topics.sh which delegates to TopicCommand.main(). Not typically imported directly by user code.

Code Reference

Source Location

  • Repository: Apache Kafka
  • File: tools/src/main/java/org/apache/kafka/tools/TopicCommand.java
  • Lines: L83-130

Signature

public class TopicCommand {
    public static void main(String... args) {
        Exit.exit(mainNoExit(args));
    }

    static void execute(String... args) throws Exception {
        TopicCommandOptions opts = new TopicCommandOptions(args);
        // Creates Admin client and routes to sub-command
        // Handles: --create, --alter, --list, --describe, --delete
    }
}

Import

bin/kafka-topics.sh --bootstrap-server localhost:9092 --list

I/O Contract

Inputs

Name Type Required Description
--bootstrap-server String Yes Kafka broker connection string
--command-config String No Client configuration properties file
Sub-command flag flag Yes One of: --create, --list, --describe, --alter, --delete

Outputs

Name Type Description
Admin client Admin Connected AdminClient for executing operations
Exit code int 0 on success, 1 on failure

Usage Examples

List All Topics

bin/kafka-topics.sh --bootstrap-server localhost:9092 --list

With Authentication

bin/kafka-topics.sh --bootstrap-server broker:9093 \
  --command-config client.properties --list

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment