[英]Why does the AdminClient not throw an exception?
我有一個Kafka AdminClient,當Kafkaserver處於活動狀態時,它將返回true,否則返回false。
private def health(server: String): Boolean = {
val props = new Properties
props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, server)
props.put(AdminClientConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG, "10000")
props.put(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, "5000")
try {
AdminClient
.create(props)
.listTopics()
.names()
.get()
true
} catch {
case _: InterruptedException => false
case _: ExecutionException => false
}
現在,我有一種情況,Kafka處於脫機狀態,並且該方法既不返回false
也不返回true
。
我究竟做錯了什么?
應用此評論,我似乎無法復制該問題,例如,以下內容
val kafkaFuture = new KafkaFutureImpl
kafkaFuture.completeExceptionally(new RuntimeException("splosh"))
println(
try {
kafkaFuture.get()
} catch {
case _: InterruptedException => "boom"
case _: ExecutionException => "crash"
}
)
輸出crash
,它顯示case _: ExecutionException
分支被正確命中。
import scala.util.Try
private def health(server: String): Boolean = {
val props = new Properties
props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, server)
props.put(AdminClientConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG, "10000")
props.put(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, "5000")
Try (
AdminClient
.create(props)
.listTopics()
.names()
.get()
).isSuccess
}
發生這種情況的原因是引發了另一個異常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.