gpt4 book ai didi

playframework - 如何使用 Akka 配置 play 应用程序在集群中运行

转载 作者:行者123 更新时间:2023-12-05 05:10:16 24 4
gpt4 key购买 nike

我有一个要在集群中运行的 PlayFramework (play-scala) 应用程序。所以我可能有几个运行此应用程序镜像的 docker 容器。我提前不知道这些的IP地址,因为云服务提供商可以动态启动和停止它们,所以我无法指定种子节点。此外,对于应用程序的每个实例,所有 application.conf 文件都应该相同吗?

如何配置 play 应用程序以使应用程序的每个实例都能发现并加入 Akka 集群?

我看过: https://www.playframework.com/documentation/2.7.x/ScalaAkka#Akka-Cluster Akka cluster setup with play framework https://github.com/lregnier/play-akka-cluster-aws

我必须使用 Akka Cluster Bootstrap 吗?因为我不能指定种子节点?

application.conf 文件中包含以下内容是否足够(取自 Cluster Usage :

akka {
actor {
provider = "cluster"
}
remote {
log-remote-lifecycle-events = off
netty.tcp {
hostname = "127.0.0.1"
port = 0
}
}

cluster {
seed-nodes = [
"akka.tcp://ClusterSystem@127.0.0.1:2551",
"akka.tcp://ClusterSystem@127.0.0.1:2552"]

# auto downing is NOT safe for production deployments.
# you may want to use it during development, read more about it in the docs.
#
# auto-down-unreachable-after = 10s
}
}

但是没有种子节点?如果是这样,节点如何发现并加入集群?

最佳答案

鉴于要求,最好的选择可能是使用 Akka Cluster Bootstrap .要运行基于容器的服务,service discovery使用 AWS ECS Kubernetes 可能更接近您的需求。

Akka Cluster Bootstrap通过自动集群引导机制解决您对没有预先分配的种子节点的需求。每个节点通过其公开的 HTTP 端点相互探测,如果没有 seed nodes存在(即不存在集群),具有“最低”地址的节点将使自己成为 seed node提示其他节点加入新形成的集群。有关详细信息,请参阅此 Akka doc re: cluster bootstrap .

如 Akka 文档中所述,Akka Cluster Bootstrap取决于模块 Akka DiscoveryAkka Management :

libraryDependencies ++= Seq(
"com.lightbend.akka.management" %% "akka-management-cluster-bootstrap" % "1.0.1",
"com.typesafe.akka" %% "akka-discovery" % "2.5.21"
)

对于 service discovery using ECS , 分配 aws-api-ecsaws-api-ecs-async (对于非阻塞 IO)到 akka.discovery.methodapplication.conf这可能看起来像下面这样:

akka {
cluster {
seed-nodes = []
seed-nodes = ${?SEED_NODES}
}
# ...
management {
cluster.bootstrap {
contact-point-discovery {
required-contact-point-nr = 2
required-contact-point-nr = ${?REQUIRED_CONTACT_POINTS}
}
}
# ...
}
discovery {
method = aws-api-ecs-async
aws-api-ecs-async {
cluster = "my-ecs-cluster"
}
}
}

对于 service discovery using Kubernetes , akka.discovery.method应该分配 kubernetes-apiapplication.conf可能如下所示:

akka {
cluster {
seed-nodes = []
seed-nodes = ${?SEED_NODES}
}
# ...
management {
cluster.bootstrap {
contact-point-discovery {
required-contact-point-nr = 2
required-contact-point-nr = ${?REQUIRED_CONTACT_POINTS}
}
}
# ...
}
discovery {
method = kubernetes-api
kubernetes-api {
pod-namespace = "default"
pod-namespace = ${?K8S_NAMESPACE}
pod-label-selector = "app=akka-cluster"
pod-label-selector = ${?K8S_SELECTOR}
pod-port-name = "cluster-mgmt-port"
pod-port-name = ${?K8S_MANAGEMENT_PORT}
}
}
}

关于playframework - 如何使用 Akka 配置 play 应用程序在集群中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56820234/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com