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

查看:372
本文介绍了如何从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消费者,它应该自动发现<$ c $中的任何主题c> kafka服务器。有获取 TopicMetadata 的API,但这需要主题名称作为输入
parameters.I需要信息服务器中存在的所有主题。

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天全站免登陆