Play Framework 2.5 Delayed Streaming Content

I am trying to stream content over HTTP using Play Framework 2.5 in Java with latency.

The problem is, I'm not sure if the result is actually streaming, so I tried to delay each element from emitting, which for some reason doesn't work.

Code

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

      

The answer can be found here .

It returns a value but does not delay it, it also sends the whole response after loading for a while. I'm not sure if initialDelay is the correct operator for the delay.

Are you sending the stream from Play correctly? I used this page as a reference https://www.playframework.com/documentation/2.5.x/StreamsMigration25

Thanks for the help!

0


source to share


1 answer


You should use delay

instead initialDelay

, which is just a delay at the start of the stream. Note that you need to define an overflow strategy when the buffer is full.



0


source







All Articles