mpettis
mpettis

Reputation: 3329

Kafka: dynamically query configurations

Is there a way to access the configuration values in server.properties without direct access to that file itself?

I thought that:

kafka-configs.sh --describe --entity-type topics --zookeeper localhost:2181

might give me what I want, but I did not see the values set in server.properties. Just the following (I set 'ddos' as my own topic from kafka-topics.sh):

Configs for topics:ddos are
Configs for topics:__consumer_offsets are segment.bytes=104857600,cleanup.policy=compact

I was thinking I'd also see globally configured options, like this from the default configuration I have:

log.retention.hours=168

Thanks in advance.

Upvotes: 9

Views: 1152

Answers (1)

Mickael Maison
Mickael Maison

Reputation: 26865

Since Kafka 0.11, you can use the AdminClient describeConfigs() API to retrieve configuration of brokers.

For example, skeleton code to retrieve configuration for broker 0:

Properties adminProps = new Properties();
adminProps.load(new FileInputStream("admin.properties"));
AdminClient admin = KafkaAdminClient.create(adminProps);

Collection<ConfigResource> resources = new ArrayList<>();
ConfigResource cr = new ConfigResource(Type.BROKER, "0");
resources.add(cr);
DescribeConfigsResult dcr = admin.describeConfigs(resources);
System.out.println(dcr.all().get());

Upvotes: 1

Related Questions