简体   繁体   中英

Akka Cluster, Cluster Sharding and Cluster singleton use cases

I am writing an Akka application and I want to use the Akka Cluster feature that Typsafe provides. I am trying to understand the main difference between Akka Cluster, Akka Cluster Singleton and Akka Cluster Sharding. To me, they seem to be providing similar things.

In my scenario I want to have a cluster that will have:

  • Stateless actors that could live in any machine (I will have a pool of them)
  • Stateless actors that I want them to live in specific machines
  • Stateful actors that could live in any machine but I need just one instance of them across the whole cluster and being able to restart the actor with its previous state if it dies.

Based on what I have read I would need Akka Cluster for the first kind, Akka Cluster Singleton for the second kind and Akka Cluster Sharding for the third kind. Is my assumption correct? I am looking for some guidance as well as any example online if you know any.

Take a look at https://github.com/dnvriend/spray-ba-sharding and https://github.com/dnvriend/spray-ba-singleton for some use case. The akka documentation is actually pretty good. Also look at the activator templates.

"Stateless actors that could live in any machine" -- this sounds like akka cluster.

"Stateless actors that I want them to live in specific machines" -- this sounds like akka cluster singleton, but you can also use roles

"being able to restart the actor with its previous state if it dies" -- this sounds like Akka Cluster Sharding with akka-persistence.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM