복사 샘플 코드. "호스트 : 포트", 점점 오류 :큐레이터 리더 선거 오류 동안 새로운 TestingServer() getConnectString에에서 지역 변경 ZK 연결 문자열에 연결 문자열이 아닌 새로운 TestingServer() getConnectString
.ERROR org.apache.curator.framework.recipes.leader.LeaderLatch getChildren() failed. rc = -6 [main-EventThread]
코드 :
import org.apache.curator.framework.CuratorFramework
import org.apache.curator.framework.CuratorFrameworkFactory
import org.apache.curator.framework.recipes.leader.{LeaderLatch,LeaderLatchListener}
import org.apache.curator.retry.ExponentialBackoffRetry
import org.apache.curator.utils.CloseableUtils
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util
object Main {
private val PATH = "/lead"
def main(args: Array[String]): Unit = {
val clients = new util.ArrayList[CuratorFramework]
val lists = new util.ArrayList[LeaderLatch]()
try {
for (i <- 0 to 2) {
val client = CuratorFrameworkFactory.newClient("xxxxx.org:2181", new ExponentialBackoffRetry(10000, 1))
//val client = CuratorFrameworkFactory.newClient(new TestingServer().getConnectString, new ExponentialBackoffRetry(10000, 1))
clients.add(client)
client.start()
client.blockUntilConnected()
val example = new LeaderLatch(client, PATH, i.toString)
lists.add(example)
example.start()
example.addListener(new LeaderLatchListener {
override def isLeader(): Unit = {
println(s"I am the lead $i")
}
override def notLeader(): Unit = {
println(s"i am not the leader any more $i")
}
})
}
Thread.sleep(5000)
println("Press enter/return to quit\n")
new BufferedReader(new InputStreamReader(System.in)).readLine
}
finally {
System.out.println("Shutting down...")
import scala.collection.JavaConversions._
for(example <- lists)
CloseableUtils.closeQuietly(example)
for (client <- clients) {
CloseableUtils.closeQuietly(client)
}
}
}
}
libs와 :
libraryDependencies += "org.apache.curator" % "apache-curator" % "4.0.0"
libraryDependencies += "org.apache.curator" % "curator-framework" % "4.0.0"
libraryDependencies += "org.apache.curator" % "curator-recipes" % "4.0.0"
libraryDependencies += "org.apache.curator" % "curator-test" % "4.0.0"
libraryDependencies += "org.apache.curator" % "curator-x-discovery" % "4.0.0"
libraryDependencies += "org.apache.curator" % "curator-x-async" % "4.0.0"