首页 > 解决方案 > Akka 块大小异常

问题描述

我正在尝试使用以下代码从 Akka 发出单个请求:

val request = HttpRequest(
  method = HttpMethods.GET,
  uri = "url"
)
val responseFuture: Future[HttpResponse] = Http().singleRequest(request)
val entityFuture: Future[HttpEntity.Strict] = responseFuture.flatMap(response => response.entity.toStrict(2.seconds))
entityFuture.map(entity => entity.data.utf8String)

但是,当我请求一个大的 json 字符串时,我得到以下异常。

akka.http.scaladsl.model.EntityStreamException: HTTP chunk size exceeds the configured limit of 1048576 bytes

我如何配置这个,我没有使用 Akka typed(我认为),只是这个:

  implicit val system = ActorSystem() 
  implicit val materializer = ActorMaterializer() 
  import system.dispatcher 

标签: scalaakka

解决方案


您可以使用以下配置来增加请求大小:

akka.http.parsing.max-chunk-size = 16m

推荐阅读