Server Sent Event
@Path("events")
@RequestScoped
public class SseResource {
@GET
@Produces(MediaType.SERVER_SENT_EVENTS)
public void eventStream(@Context Sse sse, @Context SseEventSink eventSink) {
// Resource method is invoked when a client subscribes to an event stream.
// That implies that sending events will most likely happen from different
// context - thread / event handler / etc, so common implementation of the
// resource method will store the eventSink instance and the application
// logic will retrieve it when an event should be emitted to the client.
// sending events:
eventSink.send(sse.newEvent("event1"));
}
}Last updated