The KafkaProducer have a method partitionsFor() that fetches the metadata. So 
something like this can be used to force load the metadata with max.block.ms=0


while(!gotMetadata) {
    try {
        producer.partitionsFor(topic);
        gotMetadata=true;

    } catch (TimeoutException e) {
        logger.info(String.format("KafkaProducer for topic %s is waiting for 
metadata...", topic));
        try {
            Thread.sleep(100);
        } catch (InterruptedException ignored) {

        }
    }
}

Reply via email to