Skip to content

Commit 4d7088c

Browse files
amit88265amijkum
andauthored
Added code to add new partitions in kafka topic (#18296)
Co-authored-by: amijkum <[email protected]>
1 parent a04a0c1 commit 4d7088c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.kafka;
2+
3+
import java.util.Collections;
4+
import java.util.Properties;
5+
6+
import org.apache.kafka.clients.admin.AdminClient;
7+
import org.apache.kafka.clients.admin.NewPartitions;
8+
9+
public class KafkaAddPartitionExample {
10+
11+
public static void main(String[] args) {
12+
Properties props = new Properties();
13+
props.put("bootstrap.servers", "localhost:9092");
14+
try (AdminClient adminClient = AdminClient.create(props)) {
15+
adminClient.createPartitions(Collections.singletonMap("my-topic", NewPartitions.increaseTo(3)))
16+
.all()
17+
.get();
18+
} catch (Exception e) {
19+
throw new RuntimeException(e);
20+
}
21+
}
22+
23+
}

0 commit comments

Comments
 (0)