22 Kasım 2022 Salı

Kafka Admin API

Admin Sınıfı
Şu satırı dahil ederiz
import org.apache.kafka.clients.admin.Admin;
createTopics metodu
Örnek
Şöyle yaparız
import org.apache.kafka.clients.admin.NewTopic;
import org.apache.kafka.clients.admin.CreateTopicsResult;

public void createTopic(String topicId, int partitionCount) {
  List<NewTopic> newTopics = Collections.singletonList(new NewTopic(topicId, 
     partitionCount, (short) 1));
  CreateTopicsResult createTopicsResult = admin.createTopics(newTopics);
  try {
    createTopicsResult.all().get();
  } catch (InterruptedException | ExecutionException e) {
    throw new RuntimeException(e);
  }
}


Hiç yorum yok:

Yorum Gönder