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

DevMeetup: Akka on Java

DevMeetup: Akka on Java

7a04b88e1469561db6da3818348d4b8f?s=128

Alexey Novakov

May 01, 2016
Tweet

Transcript

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

    360T)!
  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!
  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!
  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!
  5. Step 1! Client App! Order Gateway! Order Processor! Actor! OrderId

    Generator Actor! Place N orders concurrently ! NewOrder! async call!
  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!
  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. 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!
  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"!
  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!
  11. Why Actors, Akka! •  Highly-scalable! •  Loosely coupled! •  Asynchronous,

    lock-free! •  Routing, persistence, monitoring is in Akka OTB!! By design!
  12. Thank you!! Questions?! Twitter: @alexey_novakov ! ! Web: https://medium.com/se-notes-by-alexey-novakov!