我正在尝试在我的Finagle代码中发出一个外部(到Finagle服务器)REST GET请求,其URI为:http ://service.site-dev.com/subservices/list
我正在使用在以下示例中找到的客户端代码:https : //twitter.github.io/scala_school/finagle.html#client
我的代码(用Scala编写)如下所示,但是即使我设置了超时限制,它也会挂起:
val client: Service[HttpRequest, HttpResponse] = ClientBuilder()
.codec(Http())
.hosts("http://service.site-dev.com") // If >1 host, client does simple load-balancing
.hostConnectionLimit(1)
.tcpConnectTimeout(1.second)
.requestTimeout(20.seconds)
.retries(2)
.build()
val req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://service.site-dev.com/subservices/list")
val f = client(req) // Client, send the request
// Handle the response:
f onSuccess { res =>
println("got response", res)
} onFailure { exc =>
println("failed :-(", exc)
}
我怀疑我的主机参数是错误的吗?但是我想输入的是对外部REST服务的调用吗?
的字符串参数hosts
不是URI,而是应该具有格式"host:port"
(或"host1:port1,host2:port"
用于一组主机),因此将其更改为.hosts("service.site-dev.com:80")
可以解决此问题。
我没有看到NumberFormatException
您使用的是什么版本的Finagle ,我感到有些惊讶。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句