Class EventSource.Builder
- Enclosing class:
- EventSource
EventSource
builder class.
Event source builder provides methods that let you conveniently configure and subsequently build
a new EventSource
instance. You can obtain a new event source builder instance using
a static EventSource.target(endpoint)
factory method.
For example:
EventSource es = EventSource.target(endpoint).named("my source") .reconnectingEvery(5, SECONDS) .open();
- Since:
- 2.3
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Build new SSE event source pointing at a SSE streamingweb target
.Set a custom name for the event source.open()
Build new SSE event source pointing at a SSE streamingweb target
.reconnectingEvery
(long delay, TimeUnit unit) Set the initial reconnect delay to be used by the event source.Instruct event source to use persistent HTTP connections when connecting (or reconnecting) to the SSE endpoint, provided the mechanism is supported by the underlying clientConnector
.
-
Method Details
-
named
Set a custom name for the event source.At present, custom event source name is mainly useful to be able to distinguish different event source event processing threads from one another. If not set, a default name will be generated using the SSE endpoint URI.
- Parameters:
name
- custom event source name.- Returns:
- updated event source builder instance.
-
usePersistentConnections
Instruct event source to use persistent HTTP connections when connecting (or reconnecting) to the SSE endpoint, provided the mechanism is supported by the underlying clientConnector
.By default, the persistent HTTP connections are disabled for the reasons discussed in the
EventSource
javadoc.- Returns:
- updated event source builder instance.
-
reconnectingEvery
Set the initial reconnect delay to be used by the event source.Note that this value may be later overridden by the SSE endpoint using either a
retry
SSE event field or HTTP 503 + "Retry-After" mechanism as described in theEventSource
javadoc.- Parameters:
delay
- the default time to wait before attempting to recover from a connection loss.unit
- time unit of the reconnect delay parameter.- Returns:
- updated event source builder instance.
-
build
Build new SSE event source pointing at a SSE streamingweb target
.The returned event source is ready, but not
connected
to the SSE endpoint. It is expected that you will manually invoke itsopen()
method once you are ready to start receiving SSE events. In case you want to build an event source instance that is already connected to the SSE endpoint, use the event source builderopen()
method instead.Once the event source is open, the incoming events are processed by the event source in an asynchronous task that runs in an internal single-threaded
scheduled executor service
.- Returns:
- new event source instance, ready to be connected to the SSE endpoint.
- See Also:
-
open
Build new SSE event source pointing at a SSE streamingweb target
.The returned event source is already
connected
to the SSE endpoint and is processing any new incoming events. In case you want to build an event source instance that is already ready, but not automatically connected to the SSE endpoint, use the event source builderbuild()
method instead.The incoming events are processed by the event source in an asynchronous task that runs in an internal single-threaded
scheduled executor service
.- Returns:
- new event source instance, already connected to the SSE endpoint.
- See Also:
-