Cluster Aware Router前端
Cluster aware Router相對於傳統的Router區別在哪?傳統的Router是相對於一個Akka System[有待進一步確認是否能夠遠程部署?],Cluster Aware Router是指可以識別集羣的路由。集羣必然涉及到多個Akka System,因此Cluster Aware Router就是Remoting和Routing的組合。Cluster Aware Router能夠經過查找已有路由看成本身的routees,也能夠建立遠程部署到多個Node上。集羣中的節點變更會自動掛載和卸載routee。 node
兩種使用場景web
1.Router that lookup existing actors and use them as routeeswebsocket
2.Router that create new routees and deploy them on remote nodes 網絡
說一下使用的場景,在下邊的這個架構圖中客戶端經過websocket鏈接到Front-End模塊,Front-End是整個系統的門面,負責前端發送的指令解析並向下轉發。下邊M1,M2,M3是系統的業務處理模塊,接收Front-End發送過來的指令。假如系統的部署狀況是這樣的Front-End,M1,M2,M3都是集羣中的Node。Front-End的路由就要使用Look-up的方式了也就是第一種方式,由於該模塊定義了整個系統的服務接口,可是具體的業務是要由下邊的模塊去作的;M1,M2,M3各個模塊的部署能夠使用第二種遠程的部署方式,這樣部署能夠使Routees分散在各個Node節點(注意不必定非要這樣作,衡量利弊,看是否有必要。利:可控性統一調控actor數量;分佈式;充分利用計算資源。弊:分佈式帶來的網絡問題)。架構
Lookup existing actors方式socket
akka.actor.deployment {分佈式 /statsService/workerRouter {spa router = consistent-hashingrouter nr-of-instances = 100 cluster { enabled = on routees-path = "/user/statsWorker" allow-local-routees = on use-role = compute } } } |
routees-path:從那個路徑查找Actor做爲本身的Routee
allow-local-routees:是否容許本地查找,或只容許遠程查找
use-role:只從特定節點上查找
Create and deploy方式
akka.actor.deployment { /singleton/statsService/workerRouter { router = consistent-hashing nr-of-instances = 100 cluster { enabled = on max-nr-of-instances-per-node = 3 allow-local-routees = off use-role = compute } } } |
create-deploy方式就不用制定routees-path了,max-nr-of-instances-per-node:指定單個節點部署多少個routees。