问题是,当我在documentation之后返回带有大量随机行的分块响应时,并不是所有这些行都出现在浏览器中(Google Chrome,Postman)。例如。如果我发送8192行,浏览器将仅显示〜7k甚至〜4k。我的目标是使用这种方法来生成大型CSV文件。
public Result test() {
var source = Source.<ByteString>actorRef(256, OverflowStrategy.dropNew())
.mapMaterializedValue(actor -> {
new Thread(new MyRunnable(actor)).start();
return NotUsed.getInstance();
});
return ok().chunked(source);
}
// ------
public class MyRunnable implements Runnable {
private final ActorRef actor;
public MyRunnable(ActorRef actor) {
this.actor = actor;
}
public void run() {
for (var i = 0; i < 1024 * 8; i++) {
var line = String.format("%d some data goes here\n", i + 1);
actor.tell(ByteString.fromString(line), null);
}
actor.tell(new Status.Success(NotUsed.getInstance()), null);
}
}