Skip to content

Commit ceb8db0

Browse files
author
zengqiao
committed
优化查询Topic信息,Topic不存在时的错误提示
1 parent ed05a0e commit ceb8db0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

km-core/src/main/java/com/xiaojukeji/know/streaming/km/core/service/topic/impl/TopicServiceImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
import kafka.zk.TopicsZNode;
2828
import org.apache.kafka.clients.admin.*;
2929
import org.apache.kafka.common.TopicPartitionInfo;
30+
import org.apache.kafka.common.errors.UnknownTopicOrPartitionException;
3031
import org.springframework.beans.factory.annotation.Autowired;
3132
import org.springframework.dao.DuplicateKeyException;
3233
import org.springframework.stereotype.Service;
3334

3435
import java.util.*;
36+
import java.util.concurrent.ExecutionException;
3537
import java.util.concurrent.TimeUnit;
3638
import java.util.function.Function;
3739
import java.util.stream.Collectors;
@@ -84,6 +86,13 @@ public Map<Integer, List<Integer>> getTopicPartitionMapFromKafka(Long clusterPhy
8486
}
8587

8688
return partitionMap;
89+
} catch (ExecutionException e) {
90+
log.error("method=getTopicPartitionMapFromKafka||clusterPhyId={}||topicName={}||errMsg=exception", clusterPhyId, topicName, e);
91+
if (e.getCause() instanceof UnknownTopicOrPartitionException) {
92+
throw new AdminOperateException(String.format("Kafka does not host Topic:[%s]", topicName), e.getCause(), ResultStatus.KAFKA_OPERATE_FAILED);
93+
}
94+
95+
throw new AdminOperateException("get topic info from kafka failed", e.getCause(), ResultStatus.KAFKA_OPERATE_FAILED);
8796
} catch (Exception e) {
8897
log.error("method=getTopicPartitionMapFromKafka||clusterPhyId={}||topicName={}||errMsg=exception", clusterPhyId, topicName, e);
8998
throw new AdminOperateException("get topic info from kafka failed", e, ResultStatus.KAFKA_OPERATE_FAILED);

0 commit comments

Comments
 (0)