Have a look at the Cluster which has a "topic" method to get a set of all the topics.
https://kafka.apache.org/0100/javadoc/org/apache/kafka/common/Cluster.html In version 8/9, there was also the ZKUtils, but the desire is to have clients not to interrogate ZK directly. On 10/24/16, 4:32 PM, "Ben Osheroff" <b...@zendesk.com.INVALID> wrote: Hiya! I've been trying to merge https://github.com/zendesk/maxwell/pull/457, which adds a much-requested feature of Maxwell, that of being able to have a topic-per-mysql-table. When we receive a row we programmatically generate the topic name, and the first thing we do is call `KafkaProducer#partitionsFor(topic)`, so that we know how to partition the data. The problem I'm running into is in trying to detect the case where a topic doesn't exist. If auto-creation is on, `partitionsFor()` seems to correctly auto-create the topic, but if auto-creation is off the behavior is kinda wonky; kafka goes into a metadata-fetch loop, logging "Error while fetching metadata with correlation id 573 :{topic=UNKNOWN_TOPIC_OR_PARTITION}" but then ultimately throwing me back a `TimeoutException` after 60 tries or so. I can rescue/rethrow the TimeoutException, but it seems like there might be a better way that I'm missing. Any ideas? I'd ideally just like a way to fail fast and clean when the topic doesn't exist (and auto-creation is off). Thanks, Ben Osheroff zendesk.com