首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当连接字符串不是新的TestingServer().getConnectString时,策展人领导人选举错误

当连接字符串不是新的TestingServer().getConnectString时,策展人领导人选举错误
EN

Stack Overflow用户
提问于 2017-09-18 08:55:08
回答 3查看 713关注 0票数 1

将示例代码复制到本地,将zk连接字符串从新的TestingServer().getConnectString更改为"host:port",得到错误:

错误org.apache.curator.framework.recipes.leader.LeaderLatch getChildren()失败。rc = -6 main-EventThread

代码:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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"
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-09-19 03:14:06

知道了,理论上什么都没有,只是起作用了。

  • 将馆长库改为3.3.0
  • 在动物园管理员中手动创建/lead节点

动物园管理员版本: 3.4.10

因此,它看起来像是一个版本兼容性问题。

票数 1
EN

Stack Overflow用户

发布于 2017-11-06 17:08:04

您需要将动物园管理员从管理员依赖项exclude("org.apache.zookeeper","zookeeper"),中排除在外。

然后添加正确的动物园管理员依赖项"org.apache.zookeeper" % "zookeeper" % "3.4.9"

我的动物园管理员服务器是3.4.9

票数 0
EN

Stack Overflow用户

发布于 2019-04-26 11:25:29

动物园和馆长版本的兼容性。编辑maven依赖关系,例如:

代码语言:javascript
复制
<dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-x-discovery</artifactId>
            <version>4.0.1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.zookeeper</groupId>
                    <artifactId>zookeeper</artifactId>
                </exclusion>
            </exclusions>
</dependency>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46275247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档