I see that there are so many ways to handle a Route Directive, say return a Route/onSuccess/complete/completeOKWithSource etc. To me it looks like for a REST endpoint to have backpressure, I have to use completeOKWithSource like below:
get(() ->
parameter(StringUnmarshallers.INTEGER, "n", n -> {
final Source<JavaTweet, NotUsed> tws = Source.repeat(new JavaTweet("Hello World!")).take(n);
return completeOKWithSource(tws, Jackson.marshaller(), EntityStreamingSupport.json());
})
- In above, I’m returning a Source, to which akka http server can apply backpressure, right?
But, if I actually return something like a CompletableFuture, then there won’t be any backpressure support, right? Like in below example, it’s returning all or nothing with CompletableFuture.
- So even though akka http is fully async, there is no backpressure. Is my understanding correct?
get(() -> {
CompletionStage<UserRegistryActor.Users> futureUsers = PatternsCS
.ask(userRegistryActor, new UserRegistryMessages.GetUsers(), timeout)
.thenApply(obj ->(UserRegistryActor.Users) obj);
return onSuccess(() -> futureUsers,
users -> complete(StatusCodes.OK, users, Jackson.marshaller()));
})
)
Thanks!