Scala 如何处理http4s中的连接池错误?
如果Scala 如何处理http4s中的连接池错误?,scala,connection-pooling,java.util.concurrent,http4s,Scala,Connection Pooling,Java.util.concurrent,Http4s,如果http4s的blaze客户端无法连接到服务,我将尝试使用虚拟响应进行响应,但我无法找出如何处理池错误 设置连接池 import java.util.concurrent_ private val uncaughtExceptionHandler=new Thread.uncaughtExceptionHandler{ //这本应该处理得很好的,但是这个日志永远不会被打印出来 覆盖def uncaughtException(t:线程,e:可丢弃)={ logger.error(“未捕获异常”
http4s
的blaze客户端无法连接到服务,我将尝试使用虚拟响应进行响应,但我无法找出如何处理池错误
设置连接池
import java.util.concurrent_
private val uncaughtExceptionHandler=new Thread.uncaughtExceptionHandler{
//这本应该处理得很好的,但是这个日志永远不会被打印出来
覆盖def uncaughtException(t:线程,e:可丢弃)={
logger.error(“未捕获异常”)
}
}
val executor:ExecutorService=新ForkJoinPool(
Runtime.getRuntime().availableProcessors(),
ForkJoinPool.defaultForkJoinWorkerThreadFactory,
未捕获的异常处理程序,
真的
)
并使用此池执行器调用REST API——
从URI获取
但是,如果在client.fetch
中指定的uri
是我无法捕获的不可到达的端点
错误
因此,在调用client.fetch
时,我无法使用回退进行响应,因为连接池本身会抛出错误。我怎么处理这些
val client = PooledHttp1Client(
maxTotalConnections = 20,
config = BlazeClientConfig.defaultConfig.copy(customExecutor = Some(Context.executor)) // same as the executor defined above
)
// Make a call
client.fetch(Request(uri = uri)) { res =>
{
if (res.status.code === Status.Ok.code)
// do something
else
// do something else
}
ERROR org.http4s.client.PoolManager Error establishing client connection for key RequestKey(http,localhost:3000)
java.net.ConnectException: Connection refused