Akka http -ERROR :Substream Source 不能被物化不止一次如果 Payload 大小增加 [英] Akka http -ERROR :Substream Source cannot be materialized more than once If Payload size increased

查看:49
本文介绍了Akka http -ERROR :Substream Source 不能被物化不止一次如果 Payload 大小增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Akka Http,在那里我将路由定义为

I am working with Akka Http, where I have defined a route as

val route = (path(HttpConstants.CreateJob) & post) {
    (entity(as[JobDetailsEntity]) & entity(as[JobEntity])) {
      (jobDetailsEntity: JobDetailsEntity, jobEntity: JobEntity) =>
        val updatedJobEntity = jobEntity.copy(runningSince = DateTime.now().getMillis)
        val updatedJobDetailsEntity = jobDetailsEntity.copy(runningSince = DateTime.now().getMillis).copy(modify_date = DateTime.now().getMillis)
        complete {
          createJobDetails(updatedJobDetailsEntity).map(_.asJson)
          createJob(updatedJobEntity).map(_.asJson)
        }
    }

在这里,我试图在同一个 POST 调用中解组两个实体,当我的 json 有效负载 id 小即几个字节时它工作正常,一旦有效负载大小增加,即大约 10-20 kb,它就会抛出错误:

Here I am trying to unmarshal two entites in the same POST call which works when my json Payload id small i.e few bytes then its works fine , as soon as the payload size increases i.e around 10-20 kb it throws error :

子流源不能多次实现

推荐答案

请参阅 https://github.com/akka/akka-http/issues/745#issuecomment-271571342

简而言之,如果您需要对实体进行两次解组,则应首先使用 toStrict 以确保整个实体都缓冲在内存中,否则它将被第一次解组过程耗尽,而无法用于第二次.

In short, if you need to unmarshal your entity twice you should use the toStrict first to make sure the entire entity is buffered in memory, otherwise it will be drained by the first unmarshalling process and not available for the second.

如果实体足够小以适合 akka 的内部缓冲区,它只是偶然地在没有 toStrict 的情况下工作,那么实际上不涉及排空.

Only accidentally it happens to work without toStrict if the entity is small enough that it fits in akka's internal buffer, then there's actually no draining involved.

这篇关于Akka http -ERROR :Substream Source 不能被物化不止一次如果 Payload 大小增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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