本文介绍了Play Framework 2.5延迟流式传输内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用Java的Play Framework 2.5延迟通过HTTP流内容.

I have been trying to stream content through HTTP with Play Framework 2.5 in Java with a delay.

问题是我不确定结果是否真的在流式传输,这就是为什么我试图延迟每个项目的发射而由于某种原因似乎不起作用的原因.

The problem is that I am not sure if the result is actually streaming, that is why I tried to delay each item from emitting which does not seem to work for some reason.

代码

  public Result test(){

    HttpEntity http = new HttpEntity.Streamed(Source.range(0, 99999)
            .map(i -> ByteString.fromString(i.toString()))
            .initialDelay(FiniteDuration.create(200, TimeUnit.MILLISECONDS))
            , Optional.empty(), Optional.of("text/event-stream"));
    return ok().sendEntity(http);
}

可以在此处找到响应.

它确实会返回值的,但不会延迟它们,它还会在加载一段时间后发送整个响应.我不确定initialDelay是否是延迟的正确运算符.

It does return the value's but it does not delay them, it also sends the whole response after loading for a while. I am not sure if initialDelay is the right operator for a delay.

这是通过Play发送流的正确方法吗?我一直使用此页面作为参考 https://www.playframework.com/documentation/2.5.x/StreamsMigration25

Is this the right way to send a stream with Play? I have been using this page as reference https://www.playframework.com/documentation/2.5.x/StreamsMigration25

感谢您的帮助!

推荐答案

您应使用 delay ,而不是initialDelay,这只是流开始时的延迟.请注意,您需要为缓冲区已满的时间定义溢出策略.

You should use delay, rather than initialDelay, which is just a delay at start of flow. Note that you'll need to define an overflow strategy for when the buffer is full.

这篇关于Play Framework 2.5延迟流式传输内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 14:01