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

DevMeetup: Akka on Java

DevMeetup: Akka on Java

Alexey Novakov

May 01, 2016
Tweet

More Decks by Alexey Novakov

Other Decks in Programming

Transcript

  1. on Java!
    actor, persistence!
    !
    Alexey Novakov (Dev Meetup at 360T)!

    View Slide

  2. What is Actor Model?!
    http://blog.scottlogic.com/rdoyle/assets/ActorModel.png!
    •  Founded in 1973, Carl Hewitt!
    •  “One Actor is no Actor”!
    they comes as system!
    •  Single-threaded!
    •  Encapsulates states and behavior!
    •  Unit of Computation!

    View Slide

  3. Akka actor elements!
    •  ActorSystem - group of actors with common
    configuration; entry point for creating or looking up
    actors!
    •  ActorRef - immutable and serializable handle to an
    actor!
    •  Props - configuration object to create an Actor!
    •  ActorPath - unique path according to Actors tree!

    View Slide

  4. Sample App!
    1.  Generate Stock Exchange Order!
    2.  Send it to OrderProcessor actor!
    3.  Generate order id by another Actor and reply!
    4.  Log prepared order in database by one more actor!
    - Generate random fail to trigger redelivery!

    View Slide

  5. Step 1!
    Client App! Order Gateway!
    Order
    Processor!
    Actor!
    OrderId
    Generator
    Actor!
    Place N orders concurrently !
    NewOrder!
    async call!

    View Slide

  6. Step 2!
    Client App! Order Gateway!
    Order
    Processor!
    Actor!
    OrderId
    Generator
    Actor!
    OrderLog!
    Actor!
    Place N orders concurrently !
    NewOrder!
    async call!
    Dao!
    MyBatis!
    DB!

    View Slide

  7. Step 3!
    Client App! Order Gateway!
    Order
    Processor!
    Actor!
    OrderId
    Generator
    Actor!
    …..! …. Actor N!
    OrderLog!
    Actor!
    Place N orders concurrently !
    NewOrder!
    async call!
    group!
    Dao!
    MyBatis!
    DB!

    View Slide

  8. Step 3!
    Client App! Order Gateway!
    Order
    Processor!
    Actor!
    OrderId
    Generator
    Actor!
    …..! …. Actor N!
    OrderLog!
    Actor!
    Place N orders concurrently !
    NewOrder!
    async call!
    group!
    Dao!
    MyBatis!
    DB!

    View Slide

  9. Akka-Persistence!
    •  Based on “Event-Sourcing”: Command, Events!
    •  Pluggable journal and snapshot storage (LevelDB, Cassandra, MongoDB,
    others)!
    •  Can recover starting from giving sequence_id!
    •  Guarantee: no new command processed between “persist” and call of
    “handler”!
    "com.typesafe.akka" %% "akka-persistence" % "2.4.4"!
    "org.iq80.leveldb" % "leveldb" % “0.7"!
    "org.fusesource.leveldbjni" % "leveldbjni-all" % "1.8"!

    View Slide

  10. Summary!
    •  Actor incapsulates state and has mailbox (queue)!
    •  Class UntypedActor is a regular Actor on Java API!
    •  Methods:!
    •  tell(), ask()!
    •  self(), sender()!
    •  context() - select/create more actors, change state!

    View Slide

  11. Why Actors, Akka!
    •  Highly-scalable!
    •  Loosely coupled!
    •  Asynchronous, lock-free!
    •  Routing, persistence, monitoring is in Akka OTB!!
    By design!

    View Slide

  12. Thank you!!
    Questions?!
    Twitter: @alexey_novakov !
    !
    Web: https://medium.com/se-notes-by-alexey-novakov!

    View Slide