Pekko Discovery
适用于基于 Pekko 的程序使用。
依赖
要在项目中使用,请添加以下依赖:
- sbt
libraryDependencies += "me.yangbajing.nacos4s" %% "nacos-akka" % "2.0.0-SNAPSHOT"
- Maven
<dependencies> <dependency> <groupId>me.yangbajing.nacos4s</groupId> <artifactId>nacos-akka_3</artifactId> <version>2.0.0-SNAPSHOT</version> </dependency> </dependencies>
- Gradle
dependencies { implementation "me.yangbajing.nacos4s:nacos-akka_3:2.0.0-SNAPSHOT" }
配置
配置 Pekko Discovery 使用 Nacos4sNamingService
sourcepekko.discovery {
method = nacos
nacos {
// 实现了ServiceDiscovery的服务发现类完整路径
class = yangbajing.nacos4s.pekko.NacosServiceDiscovery
// 只返回健康实例
onlyHealth = true
// 只返回一个健康实例
oneHealth = true
namingConfig = nacos4s.client.naming
}
}
nacos4s.client.naming
配置见: nacos4s.client.naming
示例
更多使用示例见 测试
sourceclass NacosServiceDiscoveryTest extends ScalaTestWithActorTestKit("""
pekko.actor.testkit.typed {
default-timeout = 10.seconds
}
pekko.discovery {
method = nacos
nacos {
onlyHealth = true
oneHealth = true
}
}
nacos4s.client.naming {
serverAddr = "127.0.0.1:8848"
namespace = ""
autoRegisterInstance = true
serviceName = "me-auto-register"
port = 9999
}""".stripMargin) with AnyWordSpecLike {
"NacosServiceDiscovery" should {
"lookup" in {
val resolved = Discovery(system).discovery.lookup("me-auto-register", 10.seconds).futureValue
println(resolved)
resolved.serviceName shouldBe "me-auto-register"
resolved.addresses should not be empty
val address = resolved.addresses.head
address.port shouldBe Some(9999)
}
}
}
2.0.0*