SlideShare a Scribd company logo
Introduction to Akka
(for Scala infants !!!!)
-------
Prasanna Kumar
Excuse me !!!!!
I assume that you ,,,,
already stepped in to "Scala"land and its a JVM
language
written some Scala code and understand its
fundementals
familiar with SBT (like maven)
About this talk
is
for "Impatient"
help you to write Akka Code "right now" in
Scala
distinguish Actor model and Akka
not
teaching the partial functions and algebraic
data types in Scala
cover all aspects of Akka
Agenda
What makes us to consider Actor Model
Understanding Actor model of programming
Introducing to Akka
Akka Actor model approach
Setting up
Writing Actors using Akka (with code examples)
Moving forward (touchbase)
Q&A
What makes us to consider Actor
Model
Modern day programming need to process lot of
data in terms of
- volume
- variety
- velocity
our code started to use multiple CPU cores within
the machine or across a cluster
What makes us to consider Actor
Model (contd)
Obvious option is to consider aysnc programming
with "threads"
(atleast in Java) programming for threads is a
cumbersome
requires a lot of boiler-plate code
communicaiton between threads (with in and
outside JVM) is tedious
What makes us to consider Actor
Model (contd)
does this means the thread model is broken ??
No .. but it serves as a good foundation
just that it need better async abstraction
So how do we solve this ?
for writing concurrent and distributed programs,
we need threads to communicate easily
"Actor Model" to the rescue
What is an Actor
this model prescribes an "Actor" backed by a
thread model (by the underlying runtime or OS)
Async abstraction can be expressed as an actor in
the form of Class or function
an Actor framework
can create & manage actor
clients can communicate only by passing messages
(Async'ly) to the actor
actors can also communicate between themselves
What is an Actor
unlike Thread, an Actor
message driven
responds to certain messages from other Actors
(or non-actors)
can handle only one message at any instant of
time
Actor model of programming (contd)
Introducing Akka
Scala/Java API whcih implements the Actor model
provides a framework to create & manage actors ,
backed by JVM Thread model
Akka provides a mailbox for each actor : in-
memory queue to stage messages
clients acan send messages either by
! send or ? ask pattern (more on that later)
actor reveives messages and respond to clients
Akka actors use pattern matching to hande
messages
Lets start coding
Setting up
sbt co-ordinates
in build.sbt
name := "hyscala-akka-intro-talk"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.4.14")
open the project in your IDE to get started
plain simple actor
class PlainActor extends Actor {
def receive: Receive = {
case _ =>
}
}
actor which can respond to some messages:
class PrimitiveHandlingActor extends Actor {
def receive: Receive = {
case "hello world" => println("""received hello world """)
case 11 => println("received ")
case _ => println("some other data type")
}
}
simple shopping cart
cart and order as two actors
show case their interaction with simple messages
covers actor to actor message passing
Messages
case class Item(name: String, quantity: Int,
rate: Double)
case object Done
case class Order(item: List[Item])
Cart Actor
class CartActor extends Actor {
val items = ListBuffer[Item]()
def receive: Receive = {
case item: Item => items.+=(item)
// done with adding items to cart
case Done => ???
}
}
Cart Actor - next version
class CartActor(billingActor: ActorRef) extends Actor {
...
case Done =>
billingActor ! Order(items.toList)
items.clear()
}
Billing Actor
class BilingActor extends Actor {
def receive: Receive = {
case order: Order =>
println(s"Here your bill ${Bill(order.items.foldLeft(0.0)((a
}
}
all together ....
ouput:
Here your bill Bill(175.0)
object AkkaIntroTalk extends App {
val actorSystem = ActorSystem("actorsystem")
val billingActor = actorSystem.actorOf(Props[BillingActor],
val cartActor = actorSystem.actorOf(Props(classOf[CartAct
cartActor ! Item("Apple", 3, 20.0)
cartActor ! Item("Orange", 3, 15.0)
cartActor ! Item("Butter", 1, 70.0)
cartActor ! Done
}
Learning Akka
Online
Akka Docs
Let it crash - blog
Books
Learning Akka
Reactive Programming with Scala and Akka -
(I've authored this book)
Moving forward (touchbase)
Actor heirarchy
FSM
Load Balacing
Akka Clustering
Akka HTTP
Takeaway
https://github.com/prassee/hyscala-akka-intro-
talk/tree/master
Q&A
Akka introtalk HyScala DEC 2016

More Related Content

PDF
Xtend - better java with -less- noise
Neeraj Bhusare
 
PPTX
Introduction to Scala language
Aaqib Pervaiz
 
PDF
Functional programming with Xtend
Sven Efftinge
 
PPTX
Javascript functions
Alaref Abushaala
 
PPTX
Advance JS and oop
Abuzer Firdousi
 
PPTX
JavaScript operators
Vivek Kumar
 
PPTX
Scope demystified - AngularJS
Sumanth krishna
 
Xtend - better java with -less- noise
Neeraj Bhusare
 
Introduction to Scala language
Aaqib Pervaiz
 
Functional programming with Xtend
Sven Efftinge
 
Javascript functions
Alaref Abushaala
 
Advance JS and oop
Abuzer Firdousi
 
JavaScript operators
Vivek Kumar
 
Scope demystified - AngularJS
Sumanth krishna
 

What's hot (20)

PPTX
Zend Studio Tips and Tricks
Roy Ganor
 
PDF
Xtext Webinar
Heiko Behrens
 
PDF
Use the @types, Luke
Brooklyn Zelenka
 
PPT
Java Script ppt
Priya Goyal
 
PDF
Javascript
Aditya Gaur
 
PPT
C#/.NET Little Pitfalls
BlackRabbitCoder
 
PPTX
Lab #2: Introduction to Javascript
Walid Ashraf
 
PDF
8 introduction to_java_script
Vijay Kalyan
 
PDF
Javascript
Vibhor Grover
 
PPT
Introduction to Javascript
Amit Tyagi
 
PPTX
javascript
Kaya Ota
 
PDF
Dart for Java Developers
Yakov Fain
 
PPTX
Virtual function and abstract class
Shweta Shah
 
PDF
Variables in Pharo5
Marcus Denker
 
PDF
TypeScript for Java Developers
Yakov Fain
 
PPTX
IOS Swift language 2nd tutorial
Hassan A-j
 
PPTX
Javascript
Nagarajan
 
PPTX
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
PPTX
Java script
Abhishek Kesharwani
 
Zend Studio Tips and Tricks
Roy Ganor
 
Xtext Webinar
Heiko Behrens
 
Use the @types, Luke
Brooklyn Zelenka
 
Java Script ppt
Priya Goyal
 
Javascript
Aditya Gaur
 
C#/.NET Little Pitfalls
BlackRabbitCoder
 
Lab #2: Introduction to Javascript
Walid Ashraf
 
8 introduction to_java_script
Vijay Kalyan
 
Javascript
Vibhor Grover
 
Introduction to Javascript
Amit Tyagi
 
javascript
Kaya Ota
 
Dart for Java Developers
Yakov Fain
 
Virtual function and abstract class
Shweta Shah
 
Variables in Pharo5
Marcus Denker
 
TypeScript for Java Developers
Yakov Fain
 
IOS Swift language 2nd tutorial
Hassan A-j
 
Javascript
Nagarajan
 
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
Java script
Abhishek Kesharwani
 
Ad

Viewers also liked (10)

PDF
Deep Introduction to Akka
patriknw
 
PDF
Akka/Actor introduction
Yuki Katada
 
PDF
Introduction to Akka
Piotr Trzpil
 
PDF
An Introduction to Akka
SoftwareMill
 
PPTX
Introduction to Akka - Atlanta Java Users Group
Roy Russo
 
PPTX
Akka Actor presentation
Gene Chang
 
PDF
Introduction to Akka
Johan Andrén
 
ODP
An Introduction to Akka http
Knoldus Inc.
 
PDF
ITFT_Inter process communication
Sneh Prabha
 
PPTX
The Actor Model - Towards Better Concurrency
Dror Bereznitsky
 
Deep Introduction to Akka
patriknw
 
Akka/Actor introduction
Yuki Katada
 
Introduction to Akka
Piotr Trzpil
 
An Introduction to Akka
SoftwareMill
 
Introduction to Akka - Atlanta Java Users Group
Roy Russo
 
Akka Actor presentation
Gene Chang
 
Introduction to Akka
Johan Andrén
 
An Introduction to Akka http
Knoldus Inc.
 
ITFT_Inter process communication
Sneh Prabha
 
The Actor Model - Towards Better Concurrency
Dror Bereznitsky
 
Ad

Similar to Akka introtalk HyScala DEC 2016 (20)

PDF
Scaling Web Apps with Akka
Maciej Matyjas
 
PDF
Akka lsug skills matter
Skills Matter
 
PDF
Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Konrad Malawski
 
PDF
Building Stateful Microservices With Akka
Yaroslav Tkachenko
 
PDF
Anatomy of a Reactive Application
Mark Wilson
 
KEY
Akka london scala_user_group
Skills Matter
 
PDF
A Survey of Concurrency Constructs
Ted Leung
 
PPTX
Akka Microservices Architecture And Design
Yaroslav Tkachenko
 
PDF
Actor based approach in practice for Swift developers
Bartosz Polaczyk
 
PDF
Build Cloud Applications with Akka and Heroku
Salesforce Developers
 
PDF
The Scala Programming Language
league
 
PPT
On Scala Slides - OSDC 2009
Michael Neale
 
PPTX
Alberto Paro - Hands on Scala.js
Scala Italy
 
PPTX
Scala Italy 2015 - Hands On ScalaJS
Alberto Paro
 
PPT
Laurens Van Den Oever Xopus Presentation
Ajax Experience 2009
 
PPTX
Module design pattern i.e. express js
Ahmed Assaf
 
PPTX
Concurrency Constructs Overview
stasimus
 
PDF
Introduction to Functional Programming with Scala
pramode_ce
 
PPSX
Moderne backends mit dem aktor programmiermodell
Damir Dobric
 
PPT
JAVA SCRIPT.pptbbdndndmdndndndndnndmmddnndn
harshithunnam715
 
Scaling Web Apps with Akka
Maciej Matyjas
 
Akka lsug skills matter
Skills Matter
 
Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Konrad Malawski
 
Building Stateful Microservices With Akka
Yaroslav Tkachenko
 
Anatomy of a Reactive Application
Mark Wilson
 
Akka london scala_user_group
Skills Matter
 
A Survey of Concurrency Constructs
Ted Leung
 
Akka Microservices Architecture And Design
Yaroslav Tkachenko
 
Actor based approach in practice for Swift developers
Bartosz Polaczyk
 
Build Cloud Applications with Akka and Heroku
Salesforce Developers
 
The Scala Programming Language
league
 
On Scala Slides - OSDC 2009
Michael Neale
 
Alberto Paro - Hands on Scala.js
Scala Italy
 
Scala Italy 2015 - Hands On ScalaJS
Alberto Paro
 
Laurens Van Den Oever Xopus Presentation
Ajax Experience 2009
 
Module design pattern i.e. express js
Ahmed Assaf
 
Concurrency Constructs Overview
stasimus
 
Introduction to Functional Programming with Scala
pramode_ce
 
Moderne backends mit dem aktor programmiermodell
Damir Dobric
 
JAVA SCRIPT.pptbbdndndmdndndndndnndmmddnndn
harshithunnam715
 

More from PrasannaKumar Sathyanarayanan (10)

PDF
Akka fsm presentation
PrasannaKumar Sathyanarayanan
 
PDF
Cps (continuation passing style) in scala
PrasannaKumar Sathyanarayanan
 
PDF
Introduction to akka chense
PrasannaKumar Sathyanarayanan
 
PDF
Finagle - an intro to rpc & a sync programming in jvm
PrasannaKumar Sathyanarayanan
 
PDF
Websocket,JSON in JEE7
PrasannaKumar Sathyanarayanan
 
PDF
Scala Introduction with play - for my CSS nerds
PrasannaKumar Sathyanarayanan
 
ODP
Producer consumerproblem
PrasannaKumar Sathyanarayanan
 
PPT
Scala presentationjune112011
PrasannaKumar Sathyanarayanan
 
Akka fsm presentation
PrasannaKumar Sathyanarayanan
 
Cps (continuation passing style) in scala
PrasannaKumar Sathyanarayanan
 
Introduction to akka chense
PrasannaKumar Sathyanarayanan
 
Finagle - an intro to rpc & a sync programming in jvm
PrasannaKumar Sathyanarayanan
 
Websocket,JSON in JEE7
PrasannaKumar Sathyanarayanan
 
Scala Introduction with play - for my CSS nerds
PrasannaKumar Sathyanarayanan
 
Producer consumerproblem
PrasannaKumar Sathyanarayanan
 
Scala presentationjune112011
PrasannaKumar Sathyanarayanan
 

Recently uploaded (20)

PDF
GYTPOL If You Give a Hacker a Host
linda296484
 
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
PDF
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
GYTPOL If You Give a Hacker a Host
linda296484
 
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
This slide provides an overview Technology
mineshkharadi333
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 

Akka introtalk HyScala DEC 2016

  • 1. Introduction to Akka (for Scala infants !!!!) ------- Prasanna Kumar
  • 2. Excuse me !!!!! I assume that you ,,,, already stepped in to "Scala"land and its a JVM language written some Scala code and understand its fundementals familiar with SBT (like maven)
  • 3. About this talk is for "Impatient" help you to write Akka Code "right now" in Scala distinguish Actor model and Akka not teaching the partial functions and algebraic data types in Scala cover all aspects of Akka
  • 4. Agenda What makes us to consider Actor Model Understanding Actor model of programming Introducing to Akka Akka Actor model approach Setting up Writing Actors using Akka (with code examples) Moving forward (touchbase) Q&A
  • 5. What makes us to consider Actor Model Modern day programming need to process lot of data in terms of - volume - variety - velocity our code started to use multiple CPU cores within the machine or across a cluster
  • 6. What makes us to consider Actor Model (contd) Obvious option is to consider aysnc programming with "threads" (atleast in Java) programming for threads is a cumbersome requires a lot of boiler-plate code communicaiton between threads (with in and outside JVM) is tedious
  • 7. What makes us to consider Actor Model (contd) does this means the thread model is broken ?? No .. but it serves as a good foundation just that it need better async abstraction
  • 8. So how do we solve this ? for writing concurrent and distributed programs, we need threads to communicate easily "Actor Model" to the rescue
  • 9. What is an Actor this model prescribes an "Actor" backed by a thread model (by the underlying runtime or OS) Async abstraction can be expressed as an actor in the form of Class or function an Actor framework can create & manage actor clients can communicate only by passing messages (Async'ly) to the actor actors can also communicate between themselves
  • 10. What is an Actor unlike Thread, an Actor message driven responds to certain messages from other Actors (or non-actors) can handle only one message at any instant of time
  • 11. Actor model of programming (contd)
  • 12. Introducing Akka Scala/Java API whcih implements the Actor model provides a framework to create & manage actors , backed by JVM Thread model Akka provides a mailbox for each actor : in- memory queue to stage messages clients acan send messages either by ! send or ? ask pattern (more on that later) actor reveives messages and respond to clients Akka actors use pattern matching to hande messages
  • 14. Setting up sbt co-ordinates in build.sbt name := "hyscala-akka-intro-talk" version := "1.0" scalaVersion := "2.11.8" libraryDependencies ++= Seq( "com.typesafe.akka" %% "akka-actor" % "2.4.14") open the project in your IDE to get started
  • 15. plain simple actor class PlainActor extends Actor { def receive: Receive = { case _ => } } actor which can respond to some messages: class PrimitiveHandlingActor extends Actor { def receive: Receive = { case "hello world" => println("""received hello world """) case 11 => println("received ") case _ => println("some other data type") } }
  • 16. simple shopping cart cart and order as two actors show case their interaction with simple messages covers actor to actor message passing
  • 17. Messages case class Item(name: String, quantity: Int, rate: Double) case object Done case class Order(item: List[Item])
  • 18. Cart Actor class CartActor extends Actor { val items = ListBuffer[Item]() def receive: Receive = { case item: Item => items.+=(item) // done with adding items to cart case Done => ??? } }
  • 19. Cart Actor - next version class CartActor(billingActor: ActorRef) extends Actor { ... case Done => billingActor ! Order(items.toList) items.clear() }
  • 20. Billing Actor class BilingActor extends Actor { def receive: Receive = { case order: Order => println(s"Here your bill ${Bill(order.items.foldLeft(0.0)((a } }
  • 21. all together .... ouput: Here your bill Bill(175.0) object AkkaIntroTalk extends App { val actorSystem = ActorSystem("actorsystem") val billingActor = actorSystem.actorOf(Props[BillingActor], val cartActor = actorSystem.actorOf(Props(classOf[CartAct cartActor ! Item("Apple", 3, 20.0) cartActor ! Item("Orange", 3, 15.0) cartActor ! Item("Butter", 1, 70.0) cartActor ! Done }
  • 22. Learning Akka Online Akka Docs Let it crash - blog Books Learning Akka Reactive Programming with Scala and Akka - (I've authored this book)
  • 23. Moving forward (touchbase) Actor heirarchy FSM Load Balacing Akka Clustering Akka HTTP
  • 25. Q&A