NLinker

Akka stream example

Feb 21st, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.78 KB | None | 0 0
  1. package com.vertigo.mapping.persistence
  2.  
  3. import akka.actor.ActorSystem
  4. import akka.stream._
  5. import akka.stream.scaladsl._
  6.  
  7. object X {
  8.   implicit val system: ActorSystem = ActorSystem("MyTest")
  9.   implicit val matt: ActorMaterializer = ActorMaterializer()
  10.  
  11.   def mainFlow(): Unit = {
  12.     val grp = RunnableGraph.fromGraph(GraphDSL.create() {
  13.       implicit builder =>
  14.         import GraphDSL.Implicits._
  15.         val src = builder.add(Source(1 to 100)).out
  16.         val flw1 = builder.add(Flow[Int].map(x => x * 10).take(20))
  17.         val flw2 = builder.add(Flow[Int].filter(x => x > 50))
  18.         val snk2 = builder.add(Sink.foreach(println)).in
  19.         src ~> flw1 ~> flw2 ~> snk2
  20.         ClosedShape
  21.     }).run
  22.   }
  23.  
  24.   def main(str: Array[String]): Unit = {
  25.     mainFlow()
  26.   }
  27. }
Add Comment
Please, Sign In to add comment