Twitter Finagle客户端:如何进行外部REST api调用?

0

我正在尝试在我的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服务的调用吗?

特拉维斯·布朗(Travis Brown)

的字符串参数hosts不是URI,而是应该具有格式"host:port"(或"host1:port1,host2:port"用于一组主机),因此将其更改为.hosts("service.site-dev.com:80")可以解决此问题。

我没有看到NumberFormatException您使用的是什么版本的Finagle ,我感到有些惊讶

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何对调用Jersey客户端API的代码进行单元化?

如何使用Google Cloud客户端库进行基于API密钥的REST调用

如何使用Postman客户端调用Twitter API

如何访问Twitter Ads API?

如何通过unix中的curl进行Twitter API调用

Twitter(Tweepy):什么算作搜索API调用?

如何使用python请求调用Twitter oEmbed API?

如何使用C#(dotnet core 3.1)进行OAuth 1 Twitter API调用

如何从外部客户端使用Google Kubernetes Engine中的Jenkins API Rest

如何进行API调用

Twitter流API-Erlang客户端

如何在rspec中模拟Twitter流客户端调用?

您如何使用Twitter Rest API

客户端与Rest-API进行通信的JS框架

在客户端进行身份验证,如何现在保护我的Java Rest API?

使用Fabric和Twitter API客户端获取“已通过Twitter进行身份验证”

如何防止客户端REST API调用阻止/使用Jersey优先处理某些API调用

如何在HTML中调用twitter API函数并显示结果?

用twitter gem进行并行调用

C#Twitter Api。如何访问Twitter的关注对象列表?

如何使用OAuth 2.0实施REST API以进行多个客户端访问

如何使用快递作为代理和XHR作为客户端通过客户端身份验证联系Twitter API

在客户端C#上调用rest api

用于 twitter API 调用的 IEnumerable 与 Rx Observable

我可以使用 Fetch 在客户端调用 Twitter API 吗?

使用访问令牌和访问秘密对 Twitter 进行 GET API 调用

如何使用 Twitter API?

如何使用 Twitter API 在 Twitter 上获取用户图像?

如何仅从静态生成的 nuxt.js 页面上的客户端进行 api 调用(graphql)?