【发布时间】:2014-10-31 03:47:48
【问题描述】:
我正在尝试在我的 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)
}
我怀疑我的 hosts 参数有误?但是我想在其中添加什么,这是对外部 REST 服务的调用?
【问题讨论】:
-
你应该使用 Future.Await 这样你的主线程就不会死掉或完成。
标签: scala rest finagle twitter-finagle