The documentation在 Http().bindAndHandle()
上说:
there is no backpressure being applied to the connections Source, i.e. all connections are being accepted at maximum rate, which, depending on the applications, might present a DoS risk!
这同样适用于 bindAndHandleAsync()
bindAndHandleSync()
。
The documentation also states甚至更高级别的系统,如文件 IO 或 TCP,我认为 HTTP 在 TCP 之上将通过 react 流机制工作。
Http().bind()
是魔法函数吗?这会施加背压吗?
如何使用 akka-streams 公开背压 HTTP 端点?
最佳答案
在 Java 中这看起来像这样
Flow<ByteString, ByteString, BoxedUnit> dataFlow = ...;
Http
.get(actorSystem)
.bind(host, port, materializer)
.to(foreach(con -> {
logger.info("Accepted connection from {}.", con.remoteAddress());
con.handleWith(dataFlow, materializer)
}))
.run(materializer);
数据流是转换传入消息并将它们映射到响应事件的任何流。这样,您将受益于所有反应流的好东西。
您也可以尝试使用 http 路由和简单的 Tcp。
关于scala - Akka HTTP 背压连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31916200/