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]| | | events | |
| | v +-------o------+ |
+----------o----------+ +----------o----------+ | | |
| | currentLastEventId | | getEvents | |ServerSentEvent |
+----------o----------+ +----------o----------+ | v |
| ^ | +-------o------+ |
| Source[ServerSentEvent, Any]| | | LastElement x Future[Option[ServerSentEvent]]|
| | v +-------o------+ |
| +----------o----------+ run | | |
| | | handle |------- |ServerSentEvent |
| +----------o----------+ | v |
| | | +-------o------+ |
| (Future[Option[ServerSentEvent]], A)| | | handler x A |
| | v +--------------+ |
| +----------o----------+ + - - - - - - - - - - - - - - - - - - - - - - - - +
| +--------------------------------o unzip | |
Future[Option[ServerSentEvent]] +----------o----------+
| | |
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