我有一个在生产环境中运行的服务,它使用以下方式调用依赖项服务:
Http().newHostConnectionPoolHttps[Promise[HttpResponse]]
每次部署新的依赖服务堆栈时,我的服务 DNS 缓存都会通过设置进行更新:
java.security.Security.setProperty("networkaddress.cache.ttl" , "60")
问题是池内的连接永远存在,并且仅在启动时解析 DNS 一次。因此它继续调用旧的依赖堆栈。
我正在寻找设置最大连接生存时间的方法。
最佳答案
Akka-http 内置了此功能, 您可以在 reference config 中查看这些设置
简而言之,您基本上必须将以下 key 放入您的配置中(最有可能是 application.conf):
akka {
io {
dns {
inet-address {
# To set the time to cache name resolutions
# Possible values:
# default: sun.net.InetAddressCachePolicy.get() and getNegative()
# forever: cache forever
# never: no caching
# n [time unit]: positive timeout with unit, for example "30 s"
positive-ttl = 20s
negative-ttl = 10s
}
}
}
}
这基本上就是您所要做的。默认情况下,连接池 TTL 已设置为合理的值,您可以找到它们 here .
关于scala - 主机级 akka-http 客户端连接的生存时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43066427/