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 KafkaAdminClient IncrementalAlterConfigs

From Leeroopedia


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

Overview

Concrete tool for incrementally altering Kafka resource configurations via the AdminClient API provided by KafkaAdminClient.

Description

The KafkaAdminClient.incrementalAlterConfigs method sends an IncrementalAlterConfigsRequest to the appropriate broker. It routes requests based on resource type: BROKER_LOGGER goes to the specific broker, BROKER configs may go to the controller, and topic configs go to the least loaded broker or controller.

Usage

Use via kafka-configs.sh --alter 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: L2845-2920

Signature

public AlterConfigsResult incrementalAlterConfigs(
    Map<ConfigResource, Collection<AlterConfigOp>> configs,
    final AlterConfigsOptions options
)

Import

import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.admin.AlterConfigOp;
import org.apache.kafka.clients.admin.AlterConfigsResult;
import org.apache.kafka.common.config.ConfigResource;

I/O Contract

Inputs

Name Type Required Description
configs Map<ConfigResource, Collection<AlterConfigOp>> Yes Map of resource to config operations (SET, DELETE, APPEND, SUBTRACT)
options AlterConfigsOptions No Options for the alter request

Outputs

Name Type Description
AlterConfigsResult AlterConfigsResult Contains KafkaFuture<Void> per resource; completes when config is applied

Usage Examples

Alter Topic Config via CLI

bin/kafka-configs.sh --bootstrap-server localhost:9092 \
  --alter --entity-type topics --entity-name my-topic \
  --add-config retention.ms=172800000

Alter Config Programmatically

import org.apache.kafka.clients.admin.*;
import org.apache.kafka.common.config.ConfigResource;

try (Admin admin = Admin.create(props)) {
    ConfigResource resource = new ConfigResource(ConfigResource.Type.TOPIC, "my-topic");
    AlterConfigOp op = new AlterConfigOp(
        new ConfigEntry("retention.ms", "172800000"),
        AlterConfigOp.OpType.SET
    );
    admin.incrementalAlterConfigs(Map.of(resource, List.of(op))).all().get();
}

Related Pages

Implements Principle

Page Connections

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