// this is part of a BidiFlow
FlowShape<Tuple2<Try<HttpResponse>, RequestResult>,
Tuple2<ByteString, Object>>
bottom =
b.graph(Flow.<Tuple2<Try<HttpResponse>, Object>>empty().
mapAsync(4, pair ->
getEntityBytes(pair._1().get(), pair._2(), materializer)
).map((pair) -> new Tuple2<>(pair._1(), pair._2())));
static Future<Tuple2<ByteString, RequestResult>>
getEntityBytes( final HttpResponse response,
final Object requestResult,
final ActorMaterializer materializer) {
return response.entity().getDataBytes().runFold(
new Tuple2(ByteString.empty(),requestResult),
(aggr, next) -> new Tuple2(aggr._1().concat(next),aggr._2()), materializer);
}
What's the use-case?
--
Cheers,
√
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
so if the user sends 4gb you want to load it all into memory and crash the jvm? :-)
What's the use-case where you can't stream it?
--
Cheers,
√
response.entity().getDataBytes().runFold
....
Happy hAkking!
--
Cheers,
√
final Flow<Pair, ByteString, BoxedUnit> bytestringFlow = Flow.of(Pair.class).flatMapConcat((Pair pair) -> {
Try<HttpResponse> responseTry = (Try<HttpResponse>) pair.first();
Source<ByteString, Object> dataBytes = responseTry.get().entity().getDataBytes();
return dataBytes;
});
val future : Future[NetworkResponse] =
Source.single(req)
.log("Start Http")
.map(req => (HttpRequest(HttpMethods.GET, Uri(req.url)), req))
.log("Map to httpRequest")
.map(httpReq => httpReq._1 -> (httpReq._2.id, httpReq._2.start))
.log("Map to request")
.via(connectionPool)
.log("after connection pool")
.map(r => (r._1.get.entity.dataBytes.runWith(Sink.head), r._2))
.log("after reading response")
.mapAsync(10)(r => r._1.map(bytes => NetworkResponse(r._2._1, r._2._2, bytes.decodeString("UTF-8"))))
.log("after map async")
.runWith(Sink.head)
future pipeTo sender
.map(r => (r._1.get.entity.dataBytes.runWith(Sink.head), r._2)
uses an implicit materializer. So your are aggregating the whole ByteBuffer in memory.