Skip to content

Instantly share code, notes, and snippets.

@auryn31
Created June 25, 2019 09:16
Show Gist options
  • Save auryn31/b5f9cae140714c14ec451f96d9ba480d to your computer and use it in GitHub Desktop.
Save auryn31/b5f9cae140714c14ec451f96d9ba480d to your computer and use it in GitHub Desktop.
@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