• Like
Akka 2.0 Reloaded
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Akka 2.0 Reloaded

  • 2,036 views
Published

Introducing Akka 2.0

Introducing Akka 2.0

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,036
On SlideShare
0
From Embeds
0
Number of Embeds
5

Actions

Shares
Downloads
15
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. 2.0 Reloaded Meetu MaltiarEmail: meetu@knoldus.com Twitter:@meetumaltiar
  • 2. Akka 2.0Akka name comes from Sami mythology is actually name of a goddess of wisdom and beauty. Akka incidentally means sister in Telugu!!
  • 3. The ProblemIt is way too hard to build => correct highly concurrent systems => truly scalable systems => self-healing, fault-tolerant systems
  • 4. What is Akka?Right abstraction with actors for concurrent, fault-tolerantand scalable applicationsFor Fault-Tolerance uses “let it crash” modelAbstraction for transparent distribution for load
  • 5. Introducing ActorsActor is an entity encapsulating behavior, state and amailbox to receive messagesFor a message received by Actor a thread is allocated to itThen Actors behavior is applied to the message andpotentially some state is changed or messages is passed toother Actors
  • 6. Introducing Actors..There is elasticity between message processing andaddition of new messages. New messages can be addedwhile actor execution is happening.When processing of messages is completed thread isdeallocated from the actor. It can be reallocated a thread ata later time
  • 7. Create Applicationimport akka.actor.ActorSystemval system =ActorSystem("firstApp")
  • 8. My First Actorimport akka.actor.{ Actor, Props }class MyFirstActor extends Actor { def receive = { case msg => println("Hello!!") }}
  • 9. Create Actorsimport akka.actor.{ ActorSystem, Props }val system = ActorSystem("firstApp")val myFirstActor =system.actorOf(Props[MyFirstActor]) MyFirstActor is an ActorRef Create a top level actor
  • 10. Stop Actorssystem stop myFirstActorAlso stops all actors in hierarchy
  • 11. Send: !myFirstActor ! “Hello” fire-forget
  • 12. Ask: ?import akka.pattern.askimplicit val timeout = Timeout(50000 milliseconds)val future = myActor ? "hello"Await.result(future, timeout.duration).asInstanceOf[Int] Returns a Future[Any]
  • 13. Replyimport akka.actor.Actorclass LongWorkingActor extends Actor { def receive = { case number: Int => sender ! (“Hi I received ” + number) }}
  • 14. RoutersRoundRobinRandomSmallestMailBoxBroadCastScatterGaherFirstCompleted
  • 15. Routers...val router =system.actorOf(Props[RouterWorkerActor].withRouter(RoundRobinRouter(nrOfInstances = 5)))
  • 16. Let It CrashFault Tolerance
  • 17. Actor Pathval actorRef =system.actorFor("akka://actorPathApp/user/parent/child")val parent = context.actorFor("..")val sibling = context.actorFor("../sibling")val refPath = actorRef.path
  • 18. Supervisionclass Supervisor extends Actor { override val supervisorStrategy =OneForOneStrategy(maxNrOfRetries = 10,withinTimeRange = 1 minute) { case _: ArithmeticException => Resume case _: NullPointerException => Restart case _: IllegalArgumentException => Stop case _: Exception => Escalate }}
  • 19. Manage Failureclass FaultTolerantService extends Actor { def receive = { case msg => println(msg) } override def preRestart(reason: Throwable, message: Option[Any]) = { // clean up before restart } override def postRestart(reason: Throwable) = { // init after restart }}
  • 20. Code Sampleshttps://github.com/meetumaltiar/AkkaKnolX
  • 21. ReferencesViktor Klang talk on Akka 2.0 at NE Scala symposiumAkka website akka.io