§Pekko Typed 的叢集分片(孵化中)
Play 提供了一個孵化模組,可與 Pekko Cluster Sharding Typed 整合。若要啟用此模組,請將下列相依性加入您的建置
- Java
-
libraryDependencies += javaClusterSharding
- Scala
-
libraryDependencies += clusterSharding
§用法
在適當包含 Cluster Sharding
作為相依性後,您可以使用相依性注入取得一個執行個體。我們已為執行時期和編譯時期相依性注入提供了一些輔助程式。
請注意,Play 僅提供 DI 機制。將可供注入的類別執行個體是 Java 的 Pekko pekko.cluster.sharding.typed.javadsl.ClusterSharding
和 Scala 的 pekko.cluster.sharding.typed.scaladsl.ClusterSharding
。
§執行時期相依性注入
執行時期相依性注入與 Play 中的任何其他執行時期 DI 模組一樣運作,表示新增相依性會自動啟用模組,且執行個體可供注入。
§編譯時期相依性注入
如果您使用編譯時期 DI,您可以使用下列元件存取 ClusterSharding
- Java
-
import play.ApplicationLoader; import play.BuiltInComponentsFromContext; import play.cluster.sharding.typed.ClusterShardingComponents; import play.controllers.AssetsComponents; import play.filters.components.HttpFiltersComponents; import play.routing.Router; public class ComponentsWithClusterSharding extends BuiltInComponentsFromContext implements ClusterShardingComponents, AssetsComponents, HttpFiltersComponents { public ComponentsWithClusterSharding(ApplicationLoader.Context context) { super(context); } @Override public Router router() { return Router.empty(); } }
- Scala
-
import play.api._ import play.api.cluster.sharding.typed.ClusterShardingComponents import play.api.routing.Router import play.api.ApplicationLoader.Context class MyApplicationLoader extends ApplicationLoader { def load(context: Context) = { new ComponentsWithClusterSharding(context).application } } class ComponentsWithClusterSharding(context: Context) extends BuiltInComponentsFromContext(context) with play.filters.HttpFiltersComponents with ClusterShardingComponents { lazy val router = Router.empty }
§叢集形成
在包含此模組時,應用程式 ActorSystem
將為叢集環境進行設定。因此,它將啟動 Pekko Remote,並預設將其繫結到埠 17355
(請參閱 Pekko 文件以瞭解如何設定不同的埠)。
此外,預期您的應用程式 Actor 系統會與您應用程式的其他執行個體形成叢集。請參閱 Pekko 文件,了解如何形成 Pekko 叢集。
下一步:協助 Play
在此文件發現錯誤?此頁面的原始程式碼可在此處找到 here。閱讀 文件指南 後,歡迎您提交拉取要求。有問題或建議要分享嗎?請前往 我們的社群論壇 與社群展開對話。