Created
December 9, 2019 00:40
-
-
Save duanebester/2d1631c9495b740478e150c08837b3a0 to your computer and use it in GitHub Desktop.
Akka WebSocket Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def greeter: Flow[Message, Message, Any] = | |
Flow[Message].mapConcat { | |
case tm: TextMessage => | |
TextMessage(Source.single("Hello ") ++ tm.textStream ++ Source.single("!")) :: Nil | |
case bm: BinaryMessage => | |
// ignore binary messages but drain content to avoid the stream being clogged | |
bm.dataStream.runWith(Sink.ignore) | |
Nil | |
} | |
val websocketRoute = | |
path("greeter") { | |
handleWebSocketMessages(greeter) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment