https://kotlinlang.org logo
#ktor
Title
# ktor
j

João Rodrigues

06/01/2021, 9:57 AM
(X-Post from #server) Hey 👋 I'm developing a backend with Ktor, loving the framework so far! In some cases, I'll have to handle several (possibly large) responses from another backend, process them and forward them to my client. For now this is all rest, no web sockets. Is there anyway in Ktor to have a constant flow of responses to the client? Something like Spring WebFlux, I'd like to have a reactive flux of responses in Ktor. Have you ever implemented such thing with Ktor? Is it even possible as the framework stands today? Did you have success with any other framework? Thanks in advance 🙏
c

christophsturm

06/01/2021, 12:23 PM
you can use coroutines in accessing the the other backend, and put the responses into a flow. and in ktor you just keep writing to the response.
d

darkmoon_uk

06/01/2021, 2:51 PM
Be warned; in case you're thinking of using WebSockets later, I found them to be completely broken when Ktor is deployed in a WAR Container and not using the Embedded engine. This is dangerous because it's likely Devs will start using Embedded then try to deploy in a Container later, only to then find it doesn't work 😱 ... https://youtrack.jetbrains.com/issue/KTOR-184
j

João Rodrigues

06/01/2021, 3:31 PM
@christophsturm thank you! I was trying that out and was not being able to see the responses as they were being emitted by the flow. turns out, it was the client's fault, because when I tried it with another client, curl, I could see the responses arriving one by one as expected.
@darkmoon_uk thank you for the heads up, wasn't aware of that!
d

darkmoon_uk

06/02/2021, 5:01 AM
@João Rodrigues You may want to vote for: https://youtrack.jetbrains.com/issue/KTOR-184
1
3 Views