Why: SSE is standardized through the EventSource API in the HTML Living Standard (often referred to as an HTML5/W3C-era standard). The server keeps an HTTP connection open and pushes events to the client.
2. How is SSE related to the HTTP streaming technique?
Why: SSE is HTTP streaming with one extra rule: the events pushed from the server are formatted according to the SSE specification.
3.SseEmitter is a subclass of which Spring class?
Why:SseEmitter extends ResponseBodyEmitter and adds support for the SSE format.
4. What should replace ___ as the return type to stream server-sent events?
@Controller
public class EventController {
@GetMapping("/events")
public ___ stream() {
......
}
}
Why: A handler method returns an SseEmitter so that Spring keeps the response open and lets you send events later.
5. What does the client receive when this code runs?
Why: Each event starts with data: and ends with a blank line, so the two events appear as separate blocks. The final blank line terminates the last event.
6. What is the second argument of send() used for here?
emitter.send("hello", MediaType.TEXT_PLAIN);
Why: The second argument tells Spring which media type to use when converting and writing the data.
7. Which method should replace ___ to end the stream normally after the last event?
Why: Each call to send() pushes one event to the client, so two calls give two events. Sending "1, 2" creates only one event. System.out.println() writes to the server console, not to the client. Calling complete() first ends the stream, so no event can be sent after it.