-
-
Save auryn31/b5f9cae140714c14ec451f96d9ba480d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Path("/cars") | |
class CarResource { | |
@Inject | |
lateinit var responseStream: CarStreamResponseOutput | |
@GET | |
@Path("sse") | |
@Produces(MediaType.SERVER_SENT_EVENTS) | |
fun getSseCars(@Context sse: Sse, @Context eventSink: SseEventSink) { | |
DataService.getDataStream(TIMEOUT).subscribe({ | |
eventSink.send(sse.newEvent(Klaxon().toJsonString(it))) | |
}, ::println, { | |
eventSink.send(sse.newEventBuilder().data("done").build()) | |
eventSink.close() | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment