SlideShare a Scribd company logo
By:
Harmeet Singh (Taara)
Sr. Software Consultant
Agenda
1. Flows
2. Operator Fusion.
3. Graph DSL.
4. Leftover.
Akka Stream: Flows
The way to perform transformations to the data as it
flows between Source and Sink.
Akka Stream: Flows
Akka Stream: Example
object StreamingCopyApp extends App {
  val spath = Paths.get("/home/harmeet/akka­stream/knolx.log")
  val source: Source[ByteString, Future[IOResult]] = 
FileIO.fromPath(spath)
  val dpath = Paths.get("/home/harmeet/akka­stream­copy")
  val sink: Sink[ByteString, Future[IOResult]] = FileIO.toPath(dpath)
  val runnableGraph: RunnableGraph[Future[IOResult]] = source.to(sink)
  implicit val system = ActorSystem("akka­stream")
  implicit val ec = system.dispatcher
  implicit  val materializer = ActorMaterializer()
  runnableGraph.run().foreach { result =>
    println(s"${result.status}, ${result.count} bytes read")
    system.terminate()
  }
}
Akka Stream: Flow Example
val frame: Flow[ByteString, String, NotUsed] = 
Framing.delimiter(ByteString("n"), 10240).map(_.decodeString("UTF8"))
val parse: Flow[String, Event, NotUsed] = Flow[String].map(Event.parsing)
val filter: Flow[Event, Event, NotUsed] = Flow[Event].filter(_.log == 
"DEBUG")
val serialize: Flow[Event, ByteString, NotUsed] = Flow[Event].map{ event =>
    ByteString(event.toJson.compactPrint)
}
val composedFlow: Flow[ByteString, ByteString, NotUsed] = frame.via(parse)
    .via(filter)
    .via(serialize)
val runnableGraph: RunnableGraph[Future[IOResult]] = 
source.via(composedFlow).toMat(sink) (Keep.right)
Akka Stream: Flow Example
val composedFlow: Flow[ByteString, ByteString, NotUsed] = 
Framing.delimiter(ByteString("n"), 10240)
    .map(_.decodeString("UTF8"))
    .map(Event.parsing)
    .filter(_.log == "DEBUG")
    .map { event =>
      ByteString(event.toJson.compactPrint)
    }
val runnableGraph: RunnableGraph[Future[IOResult]] = 
source.via(composedFlow)
    .toMat(sink) (Keep.right)
Akka Stream: Operator Fusion
Operator Fusion is used to performance optimization to
mitigate the cost of passing elements between the
different stages.
Two main consequences are:
1. Passing elements fused stages faster.
2. Fused stages no longer run in parallel.
Akka Stream: Operator Fusion
Q. How can we execute fused stages in parallel???
Ans:
1. By using async method
2. Turn off auto-fusing (akka.stream.materializer.auto­
fusing=off)
Example:
Source(List(1, 2, 3)).map(_ + 1)
.async
.map(_ * 2).to(Sink.ignore)
Akka Stream: Operator Fusion
Akka Stream: Graph DSL
What if your data flow cannot be modeled as a simple linear process?
What if process is better modeled as computation graph instead?
Akka Stream: Graph DSL
The Graph DSL is kind of diagram ASCII art – in many cases
you could translate a white board diagram of a graph into
the DSL.
A graph problem is one that typically involves the concept of
fanning out and fanning in.
●
Fanning out: Single input to multiple output.
●
Fanning in: Multiple inputs single output.
Akka Stream: Graph DSL Example
val in = Source(1 to 5)
  
      val f1 = Flow[Int].map(_ * 2)
   val f2 = Flow[Int].map(_ * 1)
Akka Stream: Graph DSL Example
val f3 = Flow[Int].map(_ * 2)
  
     val f4 = Flow[Int].map(_ + 1)
val out = Sink.foreach[Int](println)
Akka Stream: Graph DSL Example
val bcast = builder.add(Broadcast[Int](2))
val merge = builder.add(Merge[Int](2))
Akka Stream: Graph DSL Example
 in ~> f1 ~> bcast ~> f2 ~> merge ~> f4 ~> out
Akka Stream: Graph DSL Example
       bcast ~> f3 ~> merge
Akka Stream: Graph DSL Example
val graph = RunnableGraph.fromGraph(GraphDSL.create() {
    implicit builder: GraphDSL.Builder[NotUsed] =>
      import GraphDSL.Implicits._
      val in = Source(1 to 5)
      val out = Sink.foreach[Int](println)
      val f1 = Flow[Int].map(_ * 2)
      val f2 = Flow[Int].map(_ * 1)
      val f3 = Flow[Int].map(_ * 2)
      val f4 = Flow[Int].map(_ + 1)
      val bcast = builder.add(Broadcast[Int](2))
      val merge = builder.add(Merge[Int](2))
      in ~> f1 ~> bcast ~> f2 ~> merge ~> f4 ~> out
      bcast ~> f3 ~> merge
      ClosedShape
  })
Akka Stream: Graph DSL ClosedShape
Thegraph itself wasfully self-contained and complete.
OR
It doesnot haveany open input port and output port like
aclosed circuit.
Akka Stream: Partial Graphs
Whenever weneed to createareusablecomponent for
graph, which wecan useaccording to requirementswith
existing or new graph.
https://doc.akka.io/docs/akka/2.5/scala/stream/stream-graphs.html#constructing-and-combinin
Leftovers
➔ API’s
➔ Error Handling.
➔ Streaming HTTP
➔ Handling IO Stream
➔ Unit Testing
References:
✔ AkkainAction by Raymond Roestenburg, Rob Bakker, Rob Williams.
✔ MasteringAkkaby Christian Baxter
✔ https://doc.akka.io/api/akka/current/akka/stream/index.html?_ga=2.25006541
Introduction to Akka Streams [Part-II]

More Related Content

ODP
Introduction to Akka Streams [Part-I]
ODP
Understanding Spark Structured Streaming
PDF
PSUG #52 Dataflow and simplified reactive programming with Akka-streams
PDF
Javantura v3 - ELK – Big Data for DevOps – Maarten Mulders
PDF
Structured streaming in Spark
PDF
Spark Your Legacy (Spark Summit 2016)
PDF
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
PDF
Building an analytics workflow using Apache Airflow
Introduction to Akka Streams [Part-I]
Understanding Spark Structured Streaming
PSUG #52 Dataflow and simplified reactive programming with Akka-streams
Javantura v3 - ELK – Big Data for DevOps – Maarten Mulders
Structured streaming in Spark
Spark Your Legacy (Spark Summit 2016)
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
Building an analytics workflow using Apache Airflow

What's hot (20)

ODP
Introduction to Structured Streaming
PPTX
Microservices - Components
PPTX
Apache Airflow | What Is An Operator
PPTX
Airflow at lyft
PDF
Ingestion file copy using apex
PDF
Log ingestion kafka -- impala using apex
PPTX
Apache Airflow in Production
PDF
Making Structured Streaming Ready for Production
PDF
Flink Forward Berlin 2017: Pramod Bhatotia, Do Le Quoc - StreamApprox: Approx...
PDF
Javantura v3 - Logs – the missing gold mine – Franjo Žilić
PPTX
Connect S3 with Kafka using Akka Streams
PDF
Akka stream and Akka CQRS
PDF
Actionable Insights with Apache Apex at Apache Big Data 2017 by Devendra Tagare
PPTX
Flink 0.10 @ Bay Area Meetup (October 2015)
PPTX
Structured Streaming Using Spark 2.1
PDF
Spark Summit EU talk by Qifan Pu
PPTX
Reactive programming for java developers
PDF
Spark Summit EU talk by Shay Nativ and Dvir Volk
PPTX
Deep Dive into Apache Apex App Development
PPTX
University program - writing an apache apex application
Introduction to Structured Streaming
Microservices - Components
Apache Airflow | What Is An Operator
Airflow at lyft
Ingestion file copy using apex
Log ingestion kafka -- impala using apex
Apache Airflow in Production
Making Structured Streaming Ready for Production
Flink Forward Berlin 2017: Pramod Bhatotia, Do Le Quoc - StreamApprox: Approx...
Javantura v3 - Logs – the missing gold mine – Franjo Žilić
Connect S3 with Kafka using Akka Streams
Akka stream and Akka CQRS
Actionable Insights with Apache Apex at Apache Big Data 2017 by Devendra Tagare
Flink 0.10 @ Bay Area Meetup (October 2015)
Structured Streaming Using Spark 2.1
Spark Summit EU talk by Qifan Pu
Reactive programming for java developers
Spark Summit EU talk by Shay Nativ and Dvir Volk
Deep Dive into Apache Apex App Development
University program - writing an apache apex application
Ad

Similar to Introduction to Akka Streams [Part-II] (20)

PPTX
Intro to Akka Streams
PDF
A dive into akka streams: from the basics to a real-world scenario
PPTX
Stream processing from single node to a cluster
PDF
Getting Started with Akka Streams
ODP
Akka streams
PDF
Reactive Streams / Akka Streams - GeeCON Prague 2014
PDF
[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)
PDF
Akka streams - Umeå java usergroup
PDF
Reactive stream processing using Akka streams
PDF
Reactive Streams: Handling Data-Flow the Reactive Way
PDF
Akka Streams - From Zero to Kafka
PDF
Journey into Reactive Streams and Akka Streams
PDF
Streaming all the things with akka streams
PDF
Reactive streams processing using Akka Streams
PDF
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
PDF
Gearpump akka streams
PDF
A Tour of Akka Streams
PDF
A Tour of Akka-Streams
PPTX
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
PDF
Asynchronous stream processing with Akka Streams
Intro to Akka Streams
A dive into akka streams: from the basics to a real-world scenario
Stream processing from single node to a cluster
Getting Started with Akka Streams
Akka streams
Reactive Streams / Akka Streams - GeeCON Prague 2014
[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)
Akka streams - Umeå java usergroup
Reactive stream processing using Akka streams
Reactive Streams: Handling Data-Flow the Reactive Way
Akka Streams - From Zero to Kafka
Journey into Reactive Streams and Akka Streams
Streaming all the things with akka streams
Reactive streams processing using Akka Streams
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Gearpump akka streams
A Tour of Akka Streams
A Tour of Akka-Streams
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Asynchronous stream processing with Akka Streams
Ad

More from Knoldus Inc. (20)

PPTX
Angular Hydration Presentation (FrontEnd)
PPTX
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
PPTX
Self-Healing Test Automation Framework - Healenium
PPTX
Kanban Metrics Presentation (Project Management)
PPTX
Java 17 features and implementation.pptx
PPTX
Chaos Mesh Introducing Chaos in Kubernetes
PPTX
GraalVM - A Step Ahead of JVM Presentation
PPTX
Nomad by HashiCorp Presentation (DevOps)
PPTX
Nomad by HashiCorp Presentation (DevOps)
PPTX
DAPR - Distributed Application Runtime Presentation
PPTX
Introduction to Azure Virtual WAN Presentation
PPTX
Introduction to Argo Rollouts Presentation
PPTX
Intro to Azure Container App Presentation
PPTX
Insights Unveiled Test Reporting and Observability Excellence
PPTX
Introduction to Splunk Presentation (DevOps)
PPTX
Code Camp - Data Profiling and Quality Analysis Framework
PPTX
AWS: Messaging Services in AWS Presentation
PPTX
Amazon Cognito: A Primer on Authentication and Authorization
PPTX
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
PPTX
Managing State & HTTP Requests In Ionic.
Angular Hydration Presentation (FrontEnd)
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Self-Healing Test Automation Framework - Healenium
Kanban Metrics Presentation (Project Management)
Java 17 features and implementation.pptx
Chaos Mesh Introducing Chaos in Kubernetes
GraalVM - A Step Ahead of JVM Presentation
Nomad by HashiCorp Presentation (DevOps)
Nomad by HashiCorp Presentation (DevOps)
DAPR - Distributed Application Runtime Presentation
Introduction to Azure Virtual WAN Presentation
Introduction to Argo Rollouts Presentation
Intro to Azure Container App Presentation
Insights Unveiled Test Reporting and Observability Excellence
Introduction to Splunk Presentation (DevOps)
Code Camp - Data Profiling and Quality Analysis Framework
AWS: Messaging Services in AWS Presentation
Amazon Cognito: A Primer on Authentication and Authorization
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Managing State & HTTP Requests In Ionic.

Recently uploaded (20)

PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Transform Your Business with a Software ERP System
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
System and Network Administraation Chapter 3
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
L1 - Introduction to python Backend.pptx
PDF
Digital Strategies for Manufacturing Companies
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Introduction to Artificial Intelligence
PPTX
history of c programming in notes for students .pptx
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
AI in Product Development-omnex systems
PDF
top salesforce developer skills in 2025.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
PTS Company Brochure 2025 (1).pdf.......
Which alternative to Crystal Reports is best for small or large businesses.pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Transform Your Business with a Software ERP System
Adobe Illustrator 28.6 Crack My Vision of Vector Design
System and Network Administraation Chapter 3
Upgrade and Innovation Strategies for SAP ERP Customers
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Wondershare Filmora 15 Crack With Activation Key [2025
L1 - Introduction to python Backend.pptx
Digital Strategies for Manufacturing Companies
How Creative Agencies Leverage Project Management Software.pdf
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Introduction to Artificial Intelligence
history of c programming in notes for students .pptx
2025 Textile ERP Trends: SAP, Odoo & Oracle
AI in Product Development-omnex systems
top salesforce developer skills in 2025.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PTS Company Brochure 2025 (1).pdf.......

Introduction to Akka Streams [Part-II]