We're going to use cluster sharding to route messages to the appropriate actors on the servers in a cluster. We'll have many actors that will be sending messages via the ShardRegion actor, and were thinking originally we'd inject that actor as a dependency into the actors that need it as we do other dependencies (e.g., an event bus).
But since ClusterSharding.shardRegion() returns an ActorRef, presumably that could become stale (if the ShardRegion actor was restarted) and hence wouldn't make sense as an injected dependency. The alternatives I can think of are 1) obtaining the ShardRegion's ActorSelection and passing that as the dependency, or 2) passing in the shard entry name and calling ClusterSharding.shardRegion() every time to get the current ActorRef. Of these, 1) is definitely cleaner as it doesn't couple the dependent actors to ClusterSharding at all.
Am I right in assuming that the performance overhead of 1) and 2) are comparable, and negligible in the grand scheme of things, compared to sending directly to the ActorRef?
thx,
Chris