我正在尝试使用kafka使用者对象使用错误/不存在的主题名称。 以下是我在轮询线之后的日志。
WARN 19508 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient : Error while fetching metadata with correlation id 22 : {dummyTopic=LEADER_NOT_AVAILABLE}
它只在控制台上记录警告而不是抛出异常。我想处理这个场景。怎么办? 以下是我的消费者代码
Properties consumerProperties = new Properties();
//SETTING consumerProperties OBJECT HERE AND USING IT TO CREATE CONSUMER OBJECT
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(consumerProperties);
ConsumerRecords<String, String> records = null;
try{
consumer.subscribe(Arrays.asList(topic));
consumer.listTopics();
records = consumer.poll(100);
LOGGER.info("Returning records to microservice.");
}
catch(IllegalArgumentException illegalArgumentException) {
LOGGER.error("Illegal Argument Exception occurred while subscribing to topic by consumer. Message: "+illegalArgumentException.getMessage());
}
catch (KafkaException kafkaException) {
LOGGER.error("Kafka Exception occurred while consuming records by consumer. Message: "+kafkaException.getMessage());
}
catch(Exception exception){
LOGGER.error("Exception occured while creating consumer object "+exception);
}
请帮助我解决如何处理kafka消费者不存在的主题名称。对于Producer,它给出了超时异常。