Play framework How to use akka stream output to a website

The easiest way to send stream output to a web socket in Playframework using Scala.

I want WebSocket to act as a stream receiver. For example, the source generates a random number, and then goes to the receiver (Websocket), so it is sent to the client.

thanks

0
scala akka playframework akka-stream
source share
2 answers

If you are talking about the new integration of Akka streams in Play 2.5.x (still M2), then I think that this should do the job as a simple valid stream, which is an echo server (touch).

def socket = WebSocket.accept[String, String] { request => Flow[String] .map(_ + " Back") } 
+1
source share

โ€œLightestโ€ is somewhat subjective, but you might consider supporting experimental Play reactive streams, as described here .

Include the Reactive Streams integration library in your project.

 libraryDependencies += "com.typesafe.play" %% "play-streams-experimental" % "2.4.4" 

All access to the module is through the Streams object.

Here is an example that adapts the Future to a singleton publisher.

 val fut: Future[Int] = Future { ... } val pubr: Publisher[Int] = Streams.futureToPublisher(fut) 

See the Streams objects in the API documentation for more details.

0
source share

All Articles