Package org.springframework.http.codec
Class ServerSentEventHttpMessageReader
java.lang.Object
org.springframework.http.codec.ServerSentEventHttpMessageReader
- All Implemented Interfaces:
- HttpMessageReader<Object>
Reader that supports a stream of 
ServerSentEvents and also plain
 Objects which is the same as an ServerSentEvent with data only.- Since:
- 5.0
- Author:
- Sebastien Deleuze, Rossen Stoyanchev, Juergen Hoeller
- 
Constructor SummaryConstructorsConstructorDescriptionConstructor without aDecoder.ServerSentEventHttpMessageReader(Decoder<?> decoder) Constructor with JSONDecoderfor decoding to Objects.
- 
Method SummaryModifier and TypeMethodDescriptionbooleancanRead(ResolvableType elementType, MediaType mediaType) Whether the given object type is supported by this reader.Decoder<?>Return the configuredDecoder.intReturn theconfiguredbyte count limit.Return the list of media types supported by this reader.reactor.core.publisher.Flux<Object>read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) Read from the input message and decode to a stream of objects.reactor.core.publisher.Mono<Object>readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) Read from the input message and decode to a single object.voidsetMaxInMemorySize(int byteCount) Configure a limit on the maximum number of bytes per SSE event which are buffered before the event is parsed.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.http.codec.HttpMessageReadergetReadableMediaTypes, read, readMono
- 
Constructor Details- 
ServerSentEventHttpMessageReaderpublic ServerSentEventHttpMessageReader()Constructor without aDecoder. In this mode onlyStringis supported as the data of an event.
- 
ServerSentEventHttpMessageReaderConstructor with JSONDecoderfor decoding to Objects. Support for decoding toStringevent data is built-in.
 
- 
- 
Method Details- 
getDecoderReturn the configuredDecoder.
- 
setMaxInMemorySizepublic void setMaxInMemorySize(int byteCount) Configure a limit on the maximum number of bytes per SSE event which are buffered before the event is parsed.Note that the data decoder, if provided, must also be customized accordingly to raise the limit if necessary in order to be able to parse the data portion of the event.By default this is set to 256K. - Parameters:
- byteCount- the max number of bytes to buffer, or -1 for unlimited
- Since:
- 5.1.13
 
- 
getMaxInMemorySizepublic int getMaxInMemorySize()Return theconfiguredbyte count limit.- Since:
- 5.1.13
 
- 
getReadableMediaTypesDescription copied from interface:HttpMessageReaderReturn the list of media types supported by this reader. The list may not apply to every possible target element type and calls to this method should typically be guarded viacanWrite(elementType, null). The list may also exclude media types supported only for a specific element type. Alternatively, useHttpMessageReader.getReadableMediaTypes(ResolvableType)for a more precise list.- Specified by:
- getReadableMediaTypesin interface- HttpMessageReader<Object>
- Returns:
- the general list of supported media types
 
- 
canReadDescription copied from interface:HttpMessageReaderWhether the given object type is supported by this reader.- Specified by:
- canReadin interface- HttpMessageReader<Object>
- Parameters:
- elementType- the type of object to check
- mediaType- the media type for the read (possibly- null)
- Returns:
- trueif readable,- falseotherwise
 
- 
readpublic reactor.core.publisher.Flux<Object> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) Description copied from interface:HttpMessageReaderRead from the input message and decode to a stream of objects.- Specified by:
- readin interface- HttpMessageReader<Object>
- Parameters:
- elementType- the type of objects in the stream which must have been previously checked via- HttpMessageReader.canRead(ResolvableType, MediaType)
- message- the message to read from
- hints- additional information about how to read and decode the input
- Returns:
- the decoded stream of elements
 
- 
readMonopublic reactor.core.publisher.Mono<Object> readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) Description copied from interface:HttpMessageReaderRead from the input message and decode to a single object.- Specified by:
- readMonoin interface- HttpMessageReader<Object>
- Parameters:
- elementType- the type of objects in the stream which must have been previously checked via- HttpMessageReader.canRead(ResolvableType, MediaType)
- message- the message to read from
- hints- additional information about how to read and decode the input
- Returns:
- the decoded object
 
 
-