Skip to content

Instantly share code, notes, and snippets.

@colinbes
Created January 6, 2020 15:44
Show Gist options
  • Save colinbes/6523160d64c8340f0edc85accaa5055a to your computer and use it in GitHub Desktop.
Save colinbes/6523160d64c8340f0edc85accaa5055a to your computer and use it in GitHub Desktop.
Akka Source.queue for SSE
lazy val (sourceQueue, eventsSource) = Source.queue[String](Int.MaxValue, OverflowStrategy.backpressure)
.delay(1.seconds, DelayOverflowStrategy.backpressure)
.map(message => ServerSentEvent(message, Some("myEvent")))
.keepAlive(1.second, () => ServerSentEvent.heartbeat)
.toMat(BroadcastHub.sink[ServerSentEvent])(Keep.both)
.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment