1

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

Giorgos Myrianthous
  • 30,279
  • 17
  • 114
  • 133
medidriss
  • 35
  • 5

1 Answers1

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
  • 30,279
  • 17
  • 114
  • 133