如何从Java中的kafka服务器获取主题列表 [英] How to get topic list from kafka server in Java

查看:35
本文介绍了如何从Java中的kafka服务器获取主题列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 kafka 0.8 版本,而且非常新.

I am using kafka 0.8 version and very much new to it.

我想知道在 kafka 服务器 中创建的主题列表及其元数据.有没有可用的 API 来查明这一点?

I want to know the list of topics created in kafka server along with it's metadata. Is there any API available to find out this?

基本上,我需要编写一个 Java 消费者,它应该自动发现 kafka 服务器 中的任何主题.有 API 来获取 TopicMetadata,但这需要主题名称作为输入参数.我需要服务器中所有主题的信息.

Basically, I need to write a Java consumer that should auto-discover any topic in kafka server.There is API to fetch TopicMetadata, but this needs name of topic as input parameters.I need information for all topics present in server.

推荐答案

一个很好的起点是 Kafka 附带的示例 shell 脚本.在发行版的/bin 目录中,您可以使用一些 shell 脚本,其中之一是 ./kafka-topic-list.sh如果您在没有指定主题的情况下运行它,它将返回所有主题及其元数据.看:https://github.com/apache/kafka/blob/0.8/bin/kafka-list-topic.sh

A good place to start would be the sample shell scripts shipped with Kafka. In the /bin directory of the distribution there's some shell scripts you can use, one of which is ./kafka-topic-list.sh If you run that without specifying a topic, it will return all topics with their metadata. See: https://github.com/apache/kafka/blob/0.8/bin/kafka-list-topic.sh

该shell脚本依次运行:https://github.com/apache/kafka/blob/0.8/core/src/main/scala/kafka/admin/ListTopicCommand.scala

That shell script in turn runs: https://github.com/apache/kafka/blob/0.8/core/src/main/scala/kafka/admin/ListTopicCommand.scala

以上都是对0.8 Kafka版本的引用,所以如果你使用的是不同的版本(甚至是点差),请务必使用github上相应的分支/标签

The above are both references to the 0.8 Kafka version, so if you're using a different version (even a point difference), be sure to use the appropriate branch/tag on github

这篇关于如何从Java中的kafka服务器获取主题列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆