Interface ServerSentEventParser
- All Known Implementing Classes:
DefaultServerSentEventParser
public interface ServerSentEventParser
Parses server-sent events (SSE) from an
InputStream,
constructs ServerSentEvent objects,
and delivers them to the provided ServerSentEventListener.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceStateful, non-blocking SSE parser. -
Method Summary
Modifier and TypeMethodDescriptionReturns a freshServerSentEventParser.Incrementalparser instance backed by the same parsing logic asparse(InputStream, ServerSentEventListener), but driven by byte chunks instead of a blockingInputStream.voidparse(InputStream httpResponseBody, ServerSentEventListener listener) Parses an input stream containing server-sent events and notifies the listener of parsed events.
-
Method Details
-
parse
Parses an input stream containing server-sent events and notifies the listener of parsed events. This method blocks until the input stream is exhausted or an error occurs.For each complete event found in the stream,
ServerSentEventListener.onEvent(ServerSentEvent)is called. If any parsing or processing error occurs,ServerSentEventListener.onError(Throwable)is called and parsing may terminate.- Parameters:
httpResponseBody- the input stream containing SSE data to parselistener- the listener to receive parsed events or error notifications
-
incremental
Returns a freshServerSentEventParser.Incrementalparser instance backed by the same parsing logic asparse(InputStream, ServerSentEventListener), but driven by byte chunks instead of a blockingInputStream. Used by the publisher-based HTTP client API to avoid pinning a thread per active stream.A parser opts into the publisher path by overriding this method. One that has not opted in throws
AsyncNotSupportedException, the same "this component is not asynchronous" marker the rest of the non-blocking API reports through its return type - this method returns a plain value, so it has nowhere to carry a failure and must throw. Existing parsers that only supportparse(InputStream, ServerSentEventListener)continue to work unchanged.- Throws:
AsyncNotSupportedException- if this parser does not support incremental parsing- Since:
- 1.20.0
-