Kafka - changing log.cleanup.policy to existing topic

1.6k Views Asked by At

I have a Kafka topic that receives many many messages. Many of them have the same key and I'm interested only in the latest messages. Looking around this topic seems perfect for the config log.cleanup.policy=compact.

Can I change the existing Kafka topic configuration adding/changing config log.cleanup.policy=compact or I have to create a new topic?

I tried to create a new topic with:

bin/kafka-topics.sh --create --topic compactedPricing \
    --partitions 1 --replication-factor 1 \
    --config cleanup.policy=compact \
    --config min.cleanable.dirty.ratio=0.001 \
    --config segment.ms=5000 \
    --bootstrap-server localhost:9094

but I received the following error:

[2022-10-25 16:01:40,114] ERROR org.apache.kafka.common.errors.TopicAuthorizationException: Authorization failed.

So, is necessary to have a peculiar authorization?

And, in any case, how can I do it?

1

There are 1 best solutions below

0
gabo On

Apparently using --alter to change topic configs is no longer supported for newer versions:

--alter Alter the number of partitions and replica assignment. Update the configuration of an existing topic via --alter is no longer supported here (the kafka-configs CLI >supports altering topic configs with a --bootstrap-server option).

The only way I managed to change this config was deleting the topic and recreating it:

kafka-topics.sh --create --config cleanup.policy=compact --topic connect-offsets --bootstrap-server kafka-01:9092