[英]Why does the AdminClient not throw an exception?
I have a Kafka AdminClient, that when Kafkaserver is active, then it will return true otherwise false. 我有一个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
}
Now, I have a scenario that Kafka is offline und the method returns neither false
or true
. 现在,我有一种情况,Kafka处于脱机状态,并且该方法既不返回false
也不返回true
。
What am I doing wrong? 我究竟做错了什么?
Applying the comment, I cannot seem to replicate the issue, for example, the following 应用此评论,我似乎无法复制该问题,例如,以下内容
val kafkaFuture = new KafkaFutureImpl
kafkaFuture.completeExceptionally(new RuntimeException("splosh"))
println(
try {
kafkaFuture.get()
} catch {
case _: InterruptedException => "boom"
case _: ExecutionException => "crash"
}
)
outputs crash
, which shows case _: ExecutionException
branch was hit correctly. 输出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
}
The reason for that happen is that another exception is getting throwed. 发生这种情况的原因是引发了另一个异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.