Server-sent Events (SSE) Connector
The SSE connector provides a continuous source of server-sent events recovering from connection failure.
Artifacts
- sbt
-
libraryDependencies += "com.lightbend.akka" %% "akka-stream-alpakka-sse" % "0.9"
- Maven
-
<dependency> <groupId>com.lightbend.akka</groupId> <artifactId>akka-stream-alpakka-sse_2.12</artifactId> <version>0.9</version> </dependency>
- Gradle
-
dependencies { compile group: "com.lightbend.akka", name: "akka-stream-alpakka-sse_2.12", version: "0.9" }
Usage
Simply define an EventSource
by giving a URI, a function for sending HTTP requests and an optional initial value for Last-Evend-ID header:
- Scala
-
val eventSource = EventSource(Uri(s"http://$host:$port"), send, Some("2"))
Then happily consume ServerSentEvent
s:
- Scala
-
val events = eventSource.throttle(1, 500.milliseconds, 1, ThrottleMode.Shaping).take(nrOfSamples).runWith(Sink.seq)
The source code for this page can be found here.