spray, scala : change the timeout

2019-07-29 18:08发布

I want to change the timeout in a spray application, but what is the simplest way to achieve this? I saw some examples on github but they are rather complicated.

thanks.

I tried this :

class MyServiceActor extends Actor with MyService {

sender ! SetRequestTimeout(scala.concurrent.duration.Duration(120,"second"))
sender ! spray.io.ConnectionTimeouts.SetIdleTimeout(scala.concurrent.duration.Duration(120,"second"))
// the HttpService trait defines only one abstract member, which
// connects the services environment to the enclosing actor or test
def actorRefFactory = context

// this actor only runs our route, but you could add
// other things here, like request stream processing
// or timeout handling
def receive = runRoute( myRoute )
}

but the timeout seems to stay at ~5 seconds.

1条回答
一纸荒年 Trace。
2楼-- · 2019-07-29 18:43

you should be able to configure the timeout using the timeout configuration value for the underlying spray can server

spray.can.server {
  request-timeout = 2s
}
查看更多
登录 后发表回答