October 2018
Intermediate to advanced
556 pages
15h 18m
English
Along with the heavyweight WebSocket, HTML 5 introduced a new way of creating static (in this case, half-duplex) connections, where the server is capable of pushing events. This technique solves similar problems to WebSocket. For example, we may declare a Server-sent events (SSE) stream using the same annotation-based programming model, but return an infinite stream of ServerSentEvent objects instead, as shown in the following example:
@RestController // (1)@RequestMapping("/sse/stocks") //class StocksController { // final Map<String, StocksService> stocksServiceMap; // ... @GetMapping // (2) public Flux<ServerSentEvent<?>> streamStocks() { // (2.1) return Flux // .fromIterable(