This stream processing stage establishes and handles a quasi-continuous EventStream from the given URI.
This stream processing stage establishes and handles a quasi-continuous EventStream from the given URI.
A single EventStream is obtained from the URI and run with the given handler. Once completed, either normally or by failure, a next one is obtained thereby sending a Last-Evend-ID header if available. Hence obtaining and handling happens in an endless cycle.
The shape of this processing stage is a source of materialized values of the given handler. To take effect it must be run. Progress (including termination) is controlled by the connected sink, e.g. a retry delay can be implemented by streaming the materialized values of the handler into a throttle.
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +---------------------+ | | trigger | | +----------o----------+ | | | Option[String]| | v | Option[String] +----------o----------+ | +------------------------------->o merge | | | +----------o----------+ | | | | | Option[String]| | | v + - - - - - - - - - - - - - - - - - - - - - - - - - + | +----------o----------+ +----------o----------+ +--------------+ | | currentLastEventId | | getEvents | | | events | | | +----------o----------+ +----------o----------+ +-------o------+ | ^ | | | | | | Source[ServerSentEvent, Any]| | ServerSentEvent | | v | | | | | +----------o----------+ run +------------------------+ | | | handle |-------| | | | | | +----------o----------+ | | | | | | v v | | | (Future[Option[ServerSentEvent]], A)| +-------o------+ +-------o------+ | | v | | handler | | lastOption | | | | +----------o----------+ +-------x------+ +-------x------+ | +--------------------------------o unzip | | A Future[Option[ServerSentEvent]] | | Future[Option[ServerSentEvent]] +----------o----------+ - - - - - - - - - - - - -x- - - - - - - - - - - - - | | (A, Future[Option[ServerSentEvent]]) | A | | v | - - - - - - - - - - - - - - - - - - - - - - - - - - - - o - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
URI with absolute path, e.g. "http://myserver/events
handler for ServerSentEvents
initial value for Last-Evend-ID header, optional
implicit ExecutionContext
implicit Materializer
source of materialized values of the handler