Reputation: 488
All materials on Cluster Sharding with Akka imply sending messages from outside the cluster to entities in the cluster. However, can entities (actors) in different sharding regions/shards of the same cluster communicate between each other? Is there some sample code available for this? (on how we send a message from one entity to another within a cluster)
Upvotes: 0
Views: 267
Reputation: 925
the short answer is "yes".
Let's elaborate:
You can view an EntiryRef
is an ActorRef
that's known to be sharded, so what you need, in any case, is a mechanism to obtain that entityRef
. That mechanism is the ClusterSharding
extension. So using:
val sharding = ClusterSharding(system)
you obtain the sharding extension which you can then use:
val counterOne: EntityRef[Counter.Command] = sharding.entityRefFor(TypeKey, "counter-1")
Upvotes: 2