I had the same question, and I do not want to leave this question unanswered. I read a lot about how I can test the connection, and most of the answers I found are checking the connection to Zk, but I really want to check the connection directly to the Kafka server.
, KafkaConsumer listTopics(). , - . TimeoutException.
def validateKafkaConnection(kafkaParams : mutable.Map[String, Object]) : Unit = {
val props = new Properties()
props.put("bootstrap.servers", kafkaParams.get("bootstrap.servers").get.toString)
props.put("group.id", kafkaParams.get("group.id").get.toString)
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer")
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer")
val simpleConsumer = new KafkaConsumer[String, String](props)
simpleConsumer.listTopics()
}
try-catch, .