atl*_*ine 5 scala akka akka-cluster akka-persistence
集群感知路由器:
val router = system.actorOf(ClusterRouterPool(
RoundRobinPool(0),
ClusterRouterPoolSettings(
totalInstances = 20,
maxInstancesPerNode = 1,
allowLocalRoutees = false,
useRole = None
)
).props(Props[Worker]), name = "router")
Run Code Online (Sandbox Code Playgroud)
在这里,我们可以向 发送消息router,该消息将发送给一系列远程路由actor。
集群分片(不考虑持久性)
class NewShoppers extends Actor {
ClusterSharding(context.system).start(
"shardshoppers",
Props(new Shopper),
ClusterShardingSettings(context.system),
Shopper.extractEntityId,
Shopper.extractShardId
)
def proxy = {
ClusterSharding(context.system).shardRegion("shardshoppers")
}
override def receive: Receive = {
case msg => proxy forward msg
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,我们可以向 发送消息proxy,该消息将发送给一系列分片actor(又名实体)。
所以,我的问题是: it seems both 2 methods can make the tasks distribute to a lot of actors. What's the design choice of above two? Which situation need which choice?
当您只想将一些工作发送到任何节点并进行一些处理时,池路由器将是,按顺序发送的两条消息可能不会最终在同一个参与者中进行处理。
集群分片适用于当您在某种类型的每个 actor 上都有一个唯一的 id,并且它们的数量太多而无法容纳在一个节点中,但您希望具有该 id 的每条消息始终最终出现在该 id 的 actor 中时。例如,将 a 建模User为实体,您希望有关该用户的所有命令都以该用户结束,但您希望在集群拓扑发生变化(删除或添加节点)时移动参与者,并且您希望它们在现有节点之间合理平衡。
| 归档时间: |
|
| 查看次数: |
1153 次 |
| 最近记录: |