Hunor Kovács
Hunor Kovács

Reputation: 1294

Akka HTTP back-pressured connections

The documentation says that on 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!

The same applies for bindAndHandleAsync() bindAndHandleSync().

The documentation also states that even higher level systems such as file IO or TCP, I suppose HTTP being on top of TCP will work by the reactive-streams mechanisms.

Is Http().bind() the magic function? Does that apply back-pressure?

How do I expose a back-pressured HTTP endpoint with akka-streams?

Upvotes: 1

Views: 1020

Answers (1)

kamiseq
kamiseq

Reputation: 593

in java this will look like this

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);

the dataFlow is any flow that transforms incomming messages and maps them to response events. this way you will benefit from all reactive stream's goodies.

you can also try with http routing and simple Tcp.

Upvotes: 3

Related Questions