public final class ServerSentEvents extends Object
Publisher or Stream.
A user simply creates a streaming HttpResponse which emits Server-Sent Events, e.g.
Server server =
Server.builder()
// Emit Server-Sent Events with the SeverSentEvent instances published by a publisher.
.service("/sse1",
(ctx, req) -> ServerSentEvents.fromPublisher(
Flux.just(ServerSentEvent.ofData("foo"), ServerSentEvent.ofData("bar"))))
// Emit Server-Sent Events with converting instances published by a publisher into
// ServerSentEvent instances.
.service("/sse2",
(ctx, req) -> ServerSentEvents.fromPublisher(
Flux.just("foo", "bar"), ServerSentEvent::ofData))
.build();
| Modifier and Type | Method and Description |
|---|---|
static HttpResponse |
fromEvent(ResponseHeaders headers,
ServerSentEvent sse)
Creates a new Server-Sent Events stream of the specified
content. |
static HttpResponse |
fromEvent(ResponseHeaders headers,
ServerSentEvent sse,
HttpHeaders trailers)
Creates a new Server-Sent Events stream of the specified
content. |
static HttpResponse |
fromEvent(ServerSentEvent sse)
Creates a new Server-Sent Events stream of the specified
content. |
static HttpResponse |
fromPublisher(org.reactivestreams.Publisher<? extends ServerSentEvent> contentPublisher)
Creates a new Server-Sent Events stream from the specified
Publisher. |
static <T> HttpResponse |
fromPublisher(org.reactivestreams.Publisher<T> contentPublisher,
Function<? super T,? extends ServerSentEvent> converter)
Creates a new Server-Sent Events stream from the specified
Publisher and converter. |
static HttpResponse |
fromPublisher(ResponseHeaders headers,
org.reactivestreams.Publisher<? extends ServerSentEvent> contentPublisher)
Creates a new Server-Sent Events stream from the specified
Publisher. |
static HttpResponse |
fromPublisher(ResponseHeaders headers,
org.reactivestreams.Publisher<? extends ServerSentEvent> contentPublisher,
HttpHeaders trailers)
Creates a new Server-Sent Events stream from the specified
Publisher. |
static <T> HttpResponse |
fromPublisher(ResponseHeaders headers,
org.reactivestreams.Publisher<T> contentPublisher,
Function<? super T,? extends ServerSentEvent> converter)
Creates a new Server-Sent Events stream from the specified
Publisher and converter. |
static <T> HttpResponse |
fromPublisher(ResponseHeaders headers,
org.reactivestreams.Publisher<T> contentPublisher,
HttpHeaders trailers,
Function<? super T,? extends ServerSentEvent> converter)
Creates a new Server-Sent Events stream from the specified
Publisher and converter. |
static HttpResponse |
fromStream(ResponseHeaders headers,
Stream<? extends ServerSentEvent> contentStream,
Executor executor)
Creates a new Server-Sent Events stream from the specified
Stream. |
static HttpResponse |
fromStream(ResponseHeaders headers,
Stream<? extends ServerSentEvent> contentStream,
HttpHeaders trailers,
Executor executor)
Creates a new Server-Sent Events stream from the specified
Stream. |
static <T> HttpResponse |
fromStream(ResponseHeaders headers,
Stream<T> contentStream,
Executor executor,
Function<? super T,? extends ServerSentEvent> converter)
Creates a new Server-Sent Events stream from the specified
Stream and converter. |
static <T> HttpResponse |
fromStream(ResponseHeaders headers,
Stream<T> contentStream,
HttpHeaders trailers,
Executor executor,
Function<? super T,? extends ServerSentEvent> converter)
Creates a new Server-Sent Events stream from the specified
Stream and converter. |
static HttpResponse |
fromStream(Stream<? extends ServerSentEvent> contentStream,
Executor executor)
Creates a new Server-Sent Events stream from the specified
Stream. |
static <T> HttpResponse |
fromStream(Stream<T> contentStream,
Executor executor,
Function<? super T,? extends ServerSentEvent> converter)
Creates a new Server-Sent Events stream from the specified
Stream and converter. |
public static HttpResponse fromPublisher(org.reactivestreams.Publisher<? extends ServerSentEvent> contentPublisher)
Publisher.contentPublisher - the Publisher which publishes the objects supposed to send as contentspublic static HttpResponse fromPublisher(ResponseHeaders headers, org.reactivestreams.Publisher<? extends ServerSentEvent> contentPublisher)
Publisher.headers - the HTTP headers supposed to sendcontentPublisher - the Publisher which publishes the objects supposed to send as contentspublic static HttpResponse fromPublisher(ResponseHeaders headers, org.reactivestreams.Publisher<? extends ServerSentEvent> contentPublisher, HttpHeaders trailers)
Publisher.headers - the HTTP headers supposed to sendcontentPublisher - the Publisher which publishes the objects supposed to send as contentstrailers - the HTTP trailerspublic static <T> HttpResponse fromPublisher(org.reactivestreams.Publisher<T> contentPublisher, Function<? super T,? extends ServerSentEvent> converter)
Publisher and converter.contentPublisher - the Publisher which publishes the objects supposed to send as contentsconverter - the converter which converts published objects into ServerSentEventspublic static <T> HttpResponse fromPublisher(ResponseHeaders headers, org.reactivestreams.Publisher<T> contentPublisher, Function<? super T,? extends ServerSentEvent> converter)
Publisher and converter.headers - the HTTP headers supposed to sendcontentPublisher - the Publisher which publishes the objects supposed to send as contentsconverter - the converter which converts published objects into ServerSentEventspublic static <T> HttpResponse fromPublisher(ResponseHeaders headers, org.reactivestreams.Publisher<T> contentPublisher, HttpHeaders trailers, Function<? super T,? extends ServerSentEvent> converter)
Publisher and converter.headers - the HTTP headers supposed to sendcontentPublisher - the Publisher which publishes the objects supposed to send as contentstrailers - the HTTP trailersconverter - the converter which converts published objects into ServerSentEventspublic static HttpResponse fromStream(Stream<? extends ServerSentEvent> contentStream, Executor executor)
Stream.contentStream - the Stream which publishes the objects supposed to send as contentsexecutor - the executor which iterates the streampublic static HttpResponse fromStream(ResponseHeaders headers, Stream<? extends ServerSentEvent> contentStream, Executor executor)
Stream.headers - the HTTP headers supposed to sendcontentStream - the Stream which publishes the objects supposed to send as contentsexecutor - the executor which iterates the streampublic static HttpResponse fromStream(ResponseHeaders headers, Stream<? extends ServerSentEvent> contentStream, HttpHeaders trailers, Executor executor)
Stream.headers - the HTTP headers supposed to sendcontentStream - the Stream which publishes the objects supposed to send as contentstrailers - the HTTP trailersexecutor - the executor which iterates the streampublic static <T> HttpResponse fromStream(Stream<T> contentStream, Executor executor, Function<? super T,? extends ServerSentEvent> converter)
Stream and converter.contentStream - the Stream which publishes the objects supposed to send as contentsexecutor - the executor which iterates the streamconverter - the converter which converts published objects into ServerSentEventspublic static <T> HttpResponse fromStream(ResponseHeaders headers, Stream<T> contentStream, Executor executor, Function<? super T,? extends ServerSentEvent> converter)
Stream and converter.headers - the HTTP headers supposed to sendcontentStream - the Stream which publishes the objects supposed to send as contentsexecutor - the executor which iterates the streamconverter - the converter which converts published objects into ServerSentEventspublic static <T> HttpResponse fromStream(ResponseHeaders headers, Stream<T> contentStream, HttpHeaders trailers, Executor executor, Function<? super T,? extends ServerSentEvent> converter)
Stream and converter.headers - the HTTP headers supposed to sendcontentStream - the Stream which publishes the objects supposed to send as contentstrailers - the HTTP trailersexecutor - the executor which iterates the streamconverter - the converter which converts published objects into ServerSentEventspublic static HttpResponse fromEvent(ServerSentEvent sse)
content.sse - the ServerSentEvent object supposed to send as contentspublic static HttpResponse fromEvent(ResponseHeaders headers, ServerSentEvent sse)
content.headers - the HTTP headers supposed to sendsse - the ServerSentEvent object supposed to send as contentspublic static HttpResponse fromEvent(ResponseHeaders headers, ServerSentEvent sse, HttpHeaders trailers)
content.headers - the HTTP headers supposed to sendsse - the ServerSentEvent object supposed to send as contentstrailers - the HTTP trailersCopyright © 2020 LeanCloud. All rights reserved.