Herdy Handoko
Well-rounded developer focusing on web technologies. Distributed computing, concurrency, and the actor model. Scala, Play, Akka, and Kotlin.
with
geekcamp Indonesia - 15 July 2017
_hhandoko
hhandoko
hhandoko
hhandoko.com
"Given a sequence of data (a stream), a series of operations is applied to each element in the stream."
"A non-hard real-time system that makes its data available at the moment a client application needs it."
[1] - Psaltis, A.G., 2017, Streaming Data, Manning Publishing, pp.8-9
"Depending on use types, the speed at which organizations can convert data into insight and then to action is considered just as critical as the ability to leverage big data, if not more so. In fact, more than half (54%) of respondents stated that they consider leveraging fast data to be more important than leveraging big data."
or
and
"Coarse-grained concurrency library and runtime, emphasizing actor-based concurrency with inspiration drawn from Erlang."
val sourceFromRange = Source(1 to 1000)
val sourceFromIterable = Source(List(1,2,3))
val sourceFromFuture = Source.fromFuture(Future.successful("hello"))
val sourceWithSingleElement = Source.single("just one")
val sourceEmittingTheSameElement = Source.repeat("again and again")
val emptySource = Source.empty
val flowDoublingElements = Flow[Int].map(_ * 2)
val flowFilteringOutOddElements = Flow[Int].filter(_ % 2 == 0)
val flowBatchingElements = Flow[Int].grouped(10)
val flowBufferingElements = Flow[String].buffer(1000, OverflowStrategy.backpressure)
val sinkPrintingOutElements = Sink.foreach[String](println(_))
val sinkCalculatingASumOfElements = Sink.fold[Int, Int](0)(_ + _)
val sinkReturningTheFirstElement = Sink.head
val sinkNoop = Sink.ignore
object FizzBuzz extends App {
implicit val sys = ActorSystem("fizzbuzz")
implicit val mat = ActorMaterializer()
val rangeSource = Source(1 to 1000)
val printlnSink = Sink.foreach[Int](println)
rangeSource
.to(printlnSink)
.run()
sys.terminate()
}
object FizzBuzz extends App {
// ...
val fizzBuzzFlow = Flow[Int].map {
case i if i % 15 == 0 => "FizzBuzz"
case i if i % 5 == 0 => "Buzz"
case i if i % 3 == 0 => "Fizz"
case i => i.toString
}
// ...
rangeSource
.via(fizzBuzzFlow) // New step added!
.to(printlnSink)
// ...
}
object FizzBuzz extends App {
// ...
val nestedSource = rangeSource.via(fizzBuzzFlow) // Nest the source and flow
// ...
val nestedFlow = prefixFlow.via(suffixFlow).via(uppercaseFlow) // Nest FizzBuzz transformations
val nestedSink = nestedFlow.to(printlnSink) // Nest transformations and sink
nestedSource
.to(nestedSink)
.run()
// ...
}
object FizzBuzz extends App {
// ...
val graph = GraphDSL.create() { implicit builder =>
// ...
import GraphDSL.Implicits._
rangeSource ~> fizzBuzzFlow ~> prefixFlow ~> suffixFlow ~> uppercaseFlow ~> printlnSink
ClosedShape
}
RunnableGraph.fromGraph(graph)
.run()
// ...
}
object FizzBuzz extends App {
// ...
val graph = GraphDSL.create() { implicit builder =>
// ...
import GraphDSL.Implicits._
SourceGraph.g ~> TransformGraph.g ~> sink
ClosedShape
}
RunnableGraph.fromGraph(graph)
.run()
// ...
}
object FizzBuzz extends App {
// ...
val graph = GraphDSL.create() { implicit builder =>
// ...
import GraphDSL.Implicits._
SourceGraph.g ~> TransformGraph.g ~> sink
ClosedShape
}
RunnableGraph.fromGraph(graph)
.run()
// ...
}
By Herdy Handoko
Presentation on Akka Streams, prepared for GeekCamp Indonesia on 15 July 2017. Link: https://www.vidio.com/watch/793734-streaming-applications-with-akka-streams-herdy-handoko
Well-rounded developer focusing on web technologies. Distributed computing, concurrency, and the actor model. Scala, Play, Akka, and Kotlin.