I want to create a topic in Kafka (2.12-2) with Java API , i tried the old codes but they don't work for me any one can help me ? i need to create a topic and then i would like to insert it into the producer and a consumer
Asked
Active
Viewed 1,156 times
1
-
this one didn't work for me maybe the reason is the version of Kafka api – medidriss Jul 15 '19 at 10:50
-
1there are multiple answer for each version under that post, have you tried everything? – Ryuzaki L Jul 15 '19 at 10:52
-
no, till now just the second one – medidriss Jul 15 '19 at 10:55
1 Answers
3
How about this one?
Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
AdminClient adminClient = KafkaAdminClient.create(props);
CreateTopicsResult res = adminClient.createTopics(
Stream.of("foo", "bar", "baz").map(
name -> new NewTopic("my-topic-name", 3, (short) 1)
).collect(Collectors.toList())
);
res.all().get();

Giorgos Myrianthous
- 36,235
- 20
- 134
- 156
-
Properties props = new Properties(); after this i can't find put() method ?? – medidriss Jul 15 '19 at 13:40
-
@medidriss What do you mean? Have you imported `Properties`? – Giorgos Myrianthous Jul 15 '19 at 14:44
-
-