【问题标题】:Finagle - upgrade ClientBuilder() to New APIs versionFinagle - 将 ClientBuilder() 升级到新的 API 版本
【发布时间】:2015-05-11 00:12:35
【问题描述】:

我有一个使用 Scala Play 的项目 - Finagle 和 ElasticSearch

我正在使用带有旧版本 API 的 Finagle 客户端,如下所示:

val client = ClientBuilder()
  .codec(Http)
  .hosts("localhost:10000,localhost:10001,localhost:10003")
  .hostConnectionLimit(1)
  .build()

这是我的代码:

https://gist.github.com/hectorgool/f217d16e2c15b122d7a7

并且工作正常,但现在我想将我的代码升级到新的 API 版本,如下所示:

val client = Http.newService("localhost:10000,localhost:10001")

我的代码的新版本在这里:

https://github.com/hectorgool/es-client/blob/master/app/lib/FinagleClient.scala

但是,现在我的项目没有编译,这行(111)有错误:

111: val client = clientFactory.apply()()

不知道怎么解决

【问题讨论】:

  • 您遇到的错误是什么?
  • 方法应用的参数不足:(请求:org.jboss.netty.handler.codec.http.HttpRequest)com.twitter.util.Future[org.jboss.netty.handler.codec. http.HttpResponse] 在服务类中。 [错误] 未指定值参数请求。

标签: scala playframework finagle


【解决方案1】:

解决了

我改变这个:

  val clientFactory: ServiceFactory[HttpRequest, HttpResponse] = ClientBuilder()
    .codec(Http())
    .hosts(hosts)
    .tcpConnectTimeout(1.second)
    .hostConnectionLimit(1)
    .buildFactory() 

为此:

val clientFactory: Service[HttpRequest, HttpResponse] = Http.newService(hosts) 

我总结一下:

val client = clientFactory.apply()()

我改变了这个:

httpResponse.onSuccess{
  response =>
    Logger.debug("Received response: " + response)
    client.close()
}.onFailure{ err: Throwable =>
    Logger.error(err.toString)      
    client.close()
}

为此:

httpResponse.onSuccess{
  response =>
    Logger.debug("Received response: " + response)
}.onFailure{ err: Throwable =>
    Logger.error(err.toString)      
}

问题的原因是:

client.close()

因为关闭了连接

【讨论】:

    猜你喜欢
    • 2016-08-29
    • 2012-04-21
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-17
    相关资源
    最近更新 更多