Hello.
Could someone please explain in the below snippet why the tellShard call always work as expected in a multi-node cluster. But the askShard call only works if an external call hits the node that hosts the shard and times out on all other nodes? Many thanks.
val sharding = ClusterSharding(system)
val messageExtractor =
new HashCodeNoEnvelopeMessageExtractor[ShoppingCartActor.CartCommand](numberOfShards = 30) {
override def entityId(message: ShoppingCartActor.CartCommand): String = "Cart"
}
val shardRegion: ActorRef[ShoppingCartActor.CartCommand] = sharding.init(
Entity(ShoppingCartActor.TypeKey) { context =>
ShoppingCartActor()
}.withMessageExtractor(messageExtractor)
)
def tellShard() = {
shardRegion ! ShoppingCartActor.Ping
}
def askShard(id: String, quantity: Int): Future[CartState] = {
shardRegion ? (ShoppingCartActor.AddItem(id, quantity, _))
}