I am new to scala. I am trying to timeout api request. I am using spray to make API request. I have spray client to get response from some other server. In my application.conf i've specified timeout of request in spray.can something like:
spray.can {
server {
idle-timeout = ${idle-timeout}
request-timeout = ${request-timeout}
request-chunk-aggregation-limit = 20m
parsing {
max-content-length = 21m
}
}
client {
idle-timeout = ${idle-timeout}
request-timeout = ${request-timeout}
response-chunk-aggregation-limit = 20m
}
}
Now, I want to override this request-timeout in one my api. I have written api something like:
def completeService(jwttoken: String, completeRequest: String): Future[HttpResponse] = {
val pipeline: HttpRequest => Future[HttpResponse] = sendReceive ~> unmarshal[HttpResponse]
val response: Future[HttpResponse] = pipeline(Post(some-remote-url, completeRequest)
~> addHeader("FROM", jwttoken))
response
}
So, how can I put request-timeout here in this method? By overriding application.conf
I tried
implicit val timeoutVal: Timeout = Timeout(scala.concurrent.duration.Duration(100, MILLISECONDS).asInstanceOf[FiniteDuration])
and I got this:
test 2020-03-06 08:48:12.147 GMT [WARN] a.k.i.AskPatternInstrumentation - Timeout triggered for ask pattern to actor [IO-HTTP] at [pipelining.scala:38]
test 2020-03-06 08:48:12.573 GMT [INFO] akka.actor.DeadLetterActorRef - Message [spray.http.HttpResponse] from Actor[akka://test-app/user/IO-HTTP/host-connector-1/1#-1105043312] to Actor[akka://test-app/deadLetters] was not deliver
I think you can add an implicit parameter
requestTimeout. The data type of that parameter is akka.util.Timeout. You can checkout this link for more details or this linkLet me know if it helps!!