我有一个场景,我需要动态读取主题名称。有没有办法获取域中所有主题的名称,然后一一读取其中的消息?
@KafkaListener(groupId="something")
someMethod(List<topics> topics){
switchTo(topics.get(0)){
read messages}
switchTo(topics.get(1)){
read messages}
...
...
...
}
最佳答案
您所需要的只是 AdminClient
中的 listTopics
:
Properties properties = new Properties();
properties.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "kafka-host:9092");
AdminClient adminClient = AdminClient.create(properties);
System.out.println(adminClient.listTopics(new ListTopicsOptions()).names().get());
关于java - 如何动态获取主题名称然后从中读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60521086/