Streaming content every X seconds #250
Comments
Hi Jaume, You have two options for streaming HTTP responses:
The following controller demonstrates some streaming HTTP responses: See also Future#sleep to wait without blocking. On Thu, Sep 17, 2015 at 8:25 AM, Jaume Pinyol Vilardell <
|
Hi @scosenza, Thank you very much for you're help. I almost have it, but the only problem is that if I use AsyncStream it wraps the requests with [] what I need to sent is
but with AsyncStream it wraps the content with
Which using Streaming response, I get the expected output but I don't see how to add headers to the response (I guess I'm too new at finatra, or scala) get("/test.stream") { request: Request =>
StreamingResponse(Buf.Utf8.apply) {
streamContent(1)
}
} I've also tried with setChunked to true, hoping for more flexibility get("/tweets/streaming_manual_writes") { request: Request =>
val response = Response()
response.setChunked(true)
response.writer.write(Buf.Utf8("hello")) before {
response.writer.write(Buf.Utf8("world")) ensure {
response.close()
}
}
Future(response)
} But I always get and error message saying:
|
Hi @scosenza, I've already solved the problem, I ended up modifying the StreamingResponse class to allow custom headers and onFailure and onCompleted callbacks. I'll do a PR with the changes, maybe someone is interested too Thank you very much for the help! |
Hello,
I don't know if it's the place to ask but I need to have a endpoint that streams data every 2 seconds without closing the connection and in different chunks. I'm struggling a little to find a solution for this case.
Is it posible to stream self-generated data in different chunks with Finatra?
Best Regards,
Jaume Pinyol
The text was updated successfully, but these errors were encountered: