I am using Spring-Boot with Kafka.
Parts of pom.xml
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<relativePath />
</parent>
....
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
...
Kafka-listner
@KafkaListener (topics = "X_OUT", autoStartup = "true")
public void listenTo (ConsumerRecord <String, String> cr, @Header (KafkaHeaders.RECEIVED_TOPIC) String topic)
{
// ...
}
After my program starts it created the topics I use automatically.
The usage of Kafka is fine – all is working as expected.
But I need to change the configuration of the topics – because of reasons.
./kafka-topics.sh --bootstrap-server localhost:9092 --describe
Topic: X_OUT TopicId: 0Rt8Sh7_RSO60O0BlQ2Zyw PartitionCount: 1 ReplicationFactor: 1 Configs: segment.bytes=1073741824
Topic: X_OUT Partition: 0 Leader: 0 Replicas: 0 Isr: 0
I need to change the topic that way.
- min.insync.replicas to 1
- ReplicationFactor to 4
Is it possible to set that in the app by Java?
The only way I found was by console-tools of Kafka.
kafka-configs.sh --bootstrap-server localhost:9092 --alter --entity-type topics --entity-name X_OUT --add-config min.insync.replicas=1
kafka-reassign-partitions.sh ... // a json-file
I do not want to use the console-tools but do it automatically in the app (at the creation or by altering).