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. 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!
  2. 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!
  3. 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!
  4. Step 1! Client App! Order Gateway! Order Processor! Actor! OrderId

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

    Generator Actor! OrderLog! Actor! Place N orders concurrently ! NewOrder! async call! Dao! MyBatis! DB!
  6. 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!
  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!
  8. 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"!
  9. 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!
  10. Why Actors, Akka! •  Highly-scalable! •  Loosely coupled! •  Asynchronous,

    lock-free! •  Routing, persistence, monitoring is in Akka OTB!! By design!