加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – Akka Http:超出配置的最大开放请求值[32]

发布时间:2020-12-16 19:16:11 所属栏目:安全 来源:网络整理
导读:我使用以下代码将一些数据发布到Server def post(endpoint: String,entity: Strict) = { Http().singleRequest(HttpRequest(uri = Notifier.notificationUrl + endpoint,method = HttpMethods.POST,entity = entity)) onComplete { case Success(response) =
我使用以下代码将一些数据发布到Server

def post(endpoint: String,entity: Strict) = {
    Http().singleRequest(HttpRequest(uri = Notifier.notificationUrl + endpoint,method = HttpMethods.POST,entity = entity)) onComplete {
      case Success(response) => response match {
        case HttpResponse(StatusCodes.OK,_,_) =>
          log.info("communicated successfully with Server")
      }
      case Failure(response) =>
        log.error("communicated failed with Server: {}",response)
    }
  }

当Notifier actor接收到如下消息时,每隔10秒调用一次

case ecMonitorInformation: ECMonitorInformation =>
  post("monitor",httpEntityFromJson(ecMonitorInformation.toJson))

问题?

我看到最初(大约5个请求进入服务器),但随后它挂起,我没有看到任何日志记录,服务器没有收到任何数据.在客户端一段时间后,我看到了以下内容

ERROR c.s.e.notification.Notifier - communicated failed with Server: java.lang.RuntimeException: Exceeded configured max-open-requests value of [32]

到底是怎么回事?我该如何解决这个问题?

解决方法

我经历了 docs并尝试了以下内容

val connectionFlow: Flow[HttpRequest,HttpResponse,Future[Http.OutgoingConnection]] =
        Http().outgoingConnection(host = "localhost",port = 8080)

然后

def httpPost(uri: String,httpEntity:Strict) {
    val responseFuture: Future[HttpResponse] =
      Source.single(HttpRequest(uri = "/monitor",entity=httpEntity))
        .via(connectionFlow)
        .runWith(Sink.head)

    responseFuture onComplete {
      case Success(response) => log.info("Communicated with Server: {}",response)
      case Failure(failure) => log.error("Communication failed with Server: {}",failure)
    }

这对我有用

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读