Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Akka with Java

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

Akka with Java

Introduction to Akka on Java platform.
Code samples:
https://bitbucket.org/pklimkowski/akka-presentation-samples

Avatar for Piotr Klimkowski

Piotr Klimkowski

August 22, 2014

Other Decks in Programming

Transcript

  1. What is Akka “Akka is an open-source toolkit and runtime

    simplifying the construction of concurrent and distributed applications on the JVM. Akka supports multiple programming models for concurrency, but it emphasizes actor-based concurrency, with inspiration drawn from Erlang.” (Wikipedia) • Initial release: 2009 • Production users: ebay, cisco, bbc, amazon …
  2. What is an Actor • Smallest unit when building an

    application • Receives and sends messages to other actors • Message is any Object - have to be immutable • Actor processes one message at a time • Form a hierarchical structure (supervision) • Could be viewed a Person
  3. Message delivery guarantees • at-most-once-delivery • “Delivery is guaranteed if

    nothing breakes” (Erlang) • guaranteed delivery possible with explicit ACK- RETRY protocol, ReliableProxy pattern • Akka Persistence - (experimental in 2.3.x) UntypedPersistentActorWithAtLeastOnceDelivery
  4. More on Actors • State • Behaviour • Children •

    and a supervision strategy to handle their faults • Mailbox - FIFO (default), priority, bounded • Termination - dead letter mailbox
  5. Actor lifecycle • preStart() - called right after starting actor,

    allows for one time initialisation • postStop() - after actor is stopped, resources cleanup • preRestart() - right before restart, by default sends termination request to children and calls postStop() • postRestart() - by default calls preStart()
  6. Lifecycle monitoring • DeathWatch - transition from alive to dead

    • ActorContext.watch() / unwatch() • Actor may monitor any other actor • Useful when depending on some other actors (not necessarily children actors)
  7. Futures • Avoid blocking as much as possible • ExecutionContext

    • Patterns.ask() / Patterns.pipe() • Callbacks - OnSuccess, OnFailure, OnComplete • Monadic methods - map(), flatMap() …
  8. Remoting • Scale out • Look up / create actors

    on remote systems • Remote death watch • Props and messages must be serialisable • Routers with remote destinations • Security
  9. Testing • akka-testkit • synchronous unit testing • TestActorRef •

    asynchronous integration testing • JavaTestKit
  10. Not this time • Configuration (Typesafe Config) • Routing •

    Clustering • Persistence • Finite State Machines • Apache Camel integration • Custom serializers