The preceding sections have introduced you to synchronous and asynchronous patterns of web service interaction. The JAX-RS 2.1 API introduces support for the publish-subscribe pattern with the inclusion of server-sent events. Server-sent events (SSEs) are a specification originally introduced as part of HTML5 by the W3C. It provides a way to establish a one-way channel from a server to a client. The connection is long running; it is reused for multiple events sent from the server, yet it is still based on the HTTP protocol. Clients request the opening of an SSE connection by using the special media type text/event-stream in the Accept header.
The publish-subscribe pattern involves two key actors, publisher and subscribers, connected via a communication channel. One or more subscribers register for the event with the publisher, and the publisher publishes the...