day*_*mer 7 scala akka spray akka-http
我使用以下代码将一些数据发布到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)
}
}
Run Code Online (Sandbox Code Playgroud)
10 seconds
当Notifier
actor接收到如下消息时,每次调用此方法
case ecMonitorInformation: ECMonitorInformation =>
post("monitor", httpEntityFromJson(ecMonitorInformation.toJson))
Run Code Online (Sandbox Code Playgroud)
问题?
我看到最初(围绕5
请求转到服务器)然后它挂起,我没有看到任何日志记录,服务器没有收到任何数据.在客户端一段时间后,我看到了以下内容
ERROR c.s.e.notification.Notifier - communicated failed with Server: java.lang.RuntimeException: Exceeded configured max-open-requests value of [32]
Run Code Online (Sandbox Code Playgroud)
到底是怎么回事?我该如何解决这个问题?
我浏览了文档并尝试了以下操作
val connectionFlow: Flow[HttpRequest, HttpResponse,
Future[Http.OutgoingConnection]] =
Http().outgoingConnection(host = "localhost", port = 8080)
Run Code Online (Sandbox Code Playgroud)
进而
def httpPost(uri: String, httpEntity:Strict) {
val responseFuture: Future[HttpResponse] =
Source.single(HttpRequest(uri = "/monitor", method = HttpMethods.POST, 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)
}
Run Code Online (Sandbox Code Playgroud)
这对我有用
归档时间: |
|
查看次数: |
5855 次 |
最近记录: |