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]
Knoldus Inc.
 
ODP
Understanding Spark Structured Streaming
Knoldus Inc.
 
PDF
PSUG #52 Dataflow and simplified reactive programming with Akka-streams
Stephane Manciot
 
PDF
Javantura v3 - ELK – Big Data for DevOps – Maarten Mulders
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
PDF
Structured streaming in Spark
Giri R Varatharajan
 
PDF
Spark Your Legacy (Spark Summit 2016)
Tzach Zohar
 
PDF
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
Romain Dorgueil
 
PDF
Building an analytics workflow using Apache Airflow
Yohei Onishi
 
Introduction to Akka Streams [Part-I]
Knoldus Inc.
 
Understanding Spark Structured Streaming
Knoldus Inc.
 
PSUG #52 Dataflow and simplified reactive programming with Akka-streams
Stephane Manciot
 
Javantura v3 - ELK – Big Data for DevOps – Maarten Mulders
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Structured streaming in Spark
Giri R Varatharajan
 
Spark Your Legacy (Spark Summit 2016)
Tzach Zohar
 
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
Romain Dorgueil
 
Building an analytics workflow using Apache Airflow
Yohei Onishi
 

What's hot (20)

ODP
Introduction to Structured Streaming
Knoldus Inc.
 
PPTX
Microservices - Components
nishasowdri
 
PPTX
Apache Airflow | What Is An Operator
Marc Lamberti
 
PPTX
Airflow at lyft
Tao Feng
 
PDF
Ingestion file copy using apex
Apache Apex
 
PDF
Log ingestion kafka -- impala using apex
Apache Apex
 
PPTX
Apache Airflow in Production
Robert Sanders
 
PDF
Making Structured Streaming Ready for Production
Databricks
 
PDF
Flink Forward Berlin 2017: Pramod Bhatotia, Do Le Quoc - StreamApprox: Approx...
Flink Forward
 
PDF
Javantura v3 - Logs – the missing gold mine – Franjo Žilić
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
PPTX
Connect S3 with Kafka using Akka Streams
Seiya Mizuno
 
PDF
Akka stream and Akka CQRS
Milan Das
 
PDF
Actionable Insights with Apache Apex at Apache Big Data 2017 by Devendra Tagare
Apache Apex
 
PPTX
Flink 0.10 @ Bay Area Meetup (October 2015)
Stephan Ewen
 
PPTX
Structured Streaming Using Spark 2.1
Sigmoid
 
PDF
Spark Summit EU talk by Qifan Pu
Spark Summit
 
PPTX
Reactive programming for java developers
Constantin Popa
 
PDF
Spark Summit EU talk by Shay Nativ and Dvir Volk
Spark Summit
 
PPTX
Deep Dive into Apache Apex App Development
Apache Apex
 
PPTX
University program - writing an apache apex application
Akshay Gore
 
Introduction to Structured Streaming
Knoldus Inc.
 
Microservices - Components
nishasowdri
 
Apache Airflow | What Is An Operator
Marc Lamberti
 
Airflow at lyft
Tao Feng
 
Ingestion file copy using apex
Apache Apex
 
Log ingestion kafka -- impala using apex
Apache Apex
 
Apache Airflow in Production
Robert Sanders
 
Making Structured Streaming Ready for Production
Databricks
 
Flink Forward Berlin 2017: Pramod Bhatotia, Do Le Quoc - StreamApprox: Approx...
Flink Forward
 
Javantura v3 - Logs – the missing gold mine – Franjo Žilić
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Connect S3 with Kafka using Akka Streams
Seiya Mizuno
 
Akka stream and Akka CQRS
Milan Das
 
Actionable Insights with Apache Apex at Apache Big Data 2017 by Devendra Tagare
Apache Apex
 
Flink 0.10 @ Bay Area Meetup (October 2015)
Stephan Ewen
 
Structured Streaming Using Spark 2.1
Sigmoid
 
Spark Summit EU talk by Qifan Pu
Spark Summit
 
Reactive programming for java developers
Constantin Popa
 
Spark Summit EU talk by Shay Nativ and Dvir Volk
Spark Summit
 
Deep Dive into Apache Apex App Development
Apache Apex
 
University program - writing an apache apex application
Akshay Gore
 
Ad

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

PPTX
Intro to Akka Streams
Michael Kendra
 
PDF
A dive into akka streams: from the basics to a real-world scenario
Gioia Ballin
 
PPTX
Stream processing from single node to a cluster
Gal Marder
 
PDF
Getting Started with Akka Streams
Knoldus Inc.
 
ODP
Akka streams
Knoldus Inc.
 
PDF
Reactive Streams / Akka Streams - GeeCON Prague 2014
Konrad Malawski
 
PDF
[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)
Konrad Malawski
 
PDF
Akka streams - UmeaĚŠ java usergroup
Johan Andrén
 
PDF
Reactive stream processing using Akka streams
Johan Andrén
 
PDF
Reactive Streams: Handling Data-Flow the Reactive Way
Roland Kuhn
 
PDF
Akka Streams - From Zero to Kafka
Mark Harrison
 
PDF
Journey into Reactive Streams and Akka Streams
Kevin Webber
 
PDF
Streaming all the things with akka streams
Johan Andrén
 
PDF
Reactive streams processing using Akka Streams
Johan Andrén
 
PDF
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Lightbend
 
PDF
Gearpump akka streams
Kam Kasravi
 
PDF
A Tour of Akka Streams
Knoldus Inc.
 
PDF
A Tour of Akka-Streams
Knoldus Inc.
 
PPTX
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lightbend
 
PDF
Asynchronous stream processing with Akka Streams
Johan Andrén
 
Intro to Akka Streams
Michael Kendra
 
A dive into akka streams: from the basics to a real-world scenario
Gioia Ballin
 
Stream processing from single node to a cluster
Gal Marder
 
Getting Started with Akka Streams
Knoldus Inc.
 
Akka streams
Knoldus Inc.
 
Reactive Streams / Akka Streams - GeeCON Prague 2014
Konrad Malawski
 
[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)
Konrad Malawski
 
Akka streams - UmeaĚŠ java usergroup
Johan Andrén
 
Reactive stream processing using Akka streams
Johan Andrén
 
Reactive Streams: Handling Data-Flow the Reactive Way
Roland Kuhn
 
Akka Streams - From Zero to Kafka
Mark Harrison
 
Journey into Reactive Streams and Akka Streams
Kevin Webber
 
Streaming all the things with akka streams
Johan Andrén
 
Reactive streams processing using Akka Streams
Johan Andrén
 
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Lightbend
 
Gearpump akka streams
Kam Kasravi
 
A Tour of Akka Streams
Knoldus Inc.
 
A Tour of Akka-Streams
Knoldus Inc.
 
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lightbend
 
Asynchronous stream processing with Akka Streams
Johan Andrén
 
Ad

More from Knoldus Inc. (20)

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

Recently uploaded (20)

PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PDF
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
PPTX
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PDF
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PPTX
Presentation about variables and constant.pptx
safalsingh810
 
PDF
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
PDF
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
PPT
Activate_Methodology_Summary presentatio
annapureddyn
 
PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
PDF
An Experience-Based Look at AI Lead Generation Pricing, Features & B2B Results
Thomas albart
 
PPTX
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
PPTX
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PDF
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
PDF
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
Presentation about variables and constant.pptx
safalsingh810
 
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
Activate_Methodology_Summary presentatio
annapureddyn
 
Role Of Python In Programing Language.pptx
jaykoshti048
 
An Experience-Based Look at AI Lead Generation Pricing, Features & B2B Results
Thomas albart
 
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 

Introduction to Akka Streams [Part-II]