Server-sent events
Typically, every interaction between a web service and its client is initiated by the client. The client sends a request (typically GET, POST, PUT, or DELETE), and then receives a response from the server. Server-sent events technology allows RESTful web services to “take the initiative” to send messages to clients; that is, to send data that is not a response to a client request. Server-sent events are useful for sending data continuously to a client for applications such as stock tickers, newsfeeds, and sports scores.
The following example illustrates how to implement this functionality into our Jakarta REST web services:
package com.ensode.jakartaeebook.serversentevents // imports omitted for brevity @ApplicationScoped @Path("serversentevents") public class SseResource { private SseBroadcaster sseBroadcaster; private OutboundSseEvent.Builder eventBuilder; private ScheduledExecutorService...