我可以为特定的管道请求设置超时和重试次数吗? [英] Can I set a timeout and number of retries on a specific pipeline request?

查看:71
本文介绍了我可以为特定的管道请求设置超时和重试次数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用spray的管道来发出这样的HTTP请求时:

When using spray's pipelining to make an HTTP request like this:

val urlpipeline = sendReceive ~> unmarshal[String]
urlpipeline { Get(url) }

有没有办法指定请求的超时时间以及该特定请求应重试的次数?

is there a way to specify a timeout for the request and the number of times it should retry for that specific request?

我发现的所有文档都只引用了配置中的内容(即使这样我似乎也无法让它工作).

All the documentation I've found only references doing in a config (and even then I can't seem to get it to work).

谢谢

推荐答案

随配置文件

我在 Akka 系统中使用 Spray 1.2.0.在我的 actor 中,我导入了现有的 Akka 系统,以便我可以使用默认的 Akka 配置文件.

With the configuration file

I use Spray 1.2.0 in an Akka system. Inside my actor, I import the existing Akka system so I can use the default Akka configuration file.

implicit val system = context.system
import context.dispatcher
val pipeline: HttpRequest => Future[HttpResponse] = sendReceive

现在您可以更改 application.conf 中的配置.

Now you can change the configuration in application.conf.

spray.can.host-connector {
    max-connections = 10
    max-retries = 3
    max-redirects = 0
    pipelining = off
    idle-timeout = 30 s
    client = ${spray.can.client}
}

在代码中

可以使用 HostConnectorSetup 更改代码中的设置,但您必须定义所有参数.(基于喷雾使用示例.)

val pipeline: Future[SendReceive] =
for (
  Http.HostConnectorInfo(connector, _) <-
  IO(Http) ? Http.HostConnectorSetup("www.spray.io", port = 80, settings = Some(new HostConnectorSettings(maxConnections = 3, maxRetries = 3, maxRedirects = 0, pipelining = false, idleTimeout = 5 seconds, connectionSettings = ClientConnectionSettings(...))))
) yield sendReceive(connector)

这篇关于我可以为特定的管道请求设置超时和重试次数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆