Skip to content

使用 Zookeeper

下载安装

可以通过 ZooKeeper官网 下载和安装 ZooKeeper。

开发使用

使用ZooKeeper,需要在项目中引入如下依赖:

<dependency>
  <groupId>org.apache.servicecomb</groupId>
  <artifactId>config-zookeeper</artifactId>
</dependency>

然后在配置文件 microservice.yaml 中增加如下配置项:

servicecomb:
  config:
    zk:
      connectString: 127.0.0.1:2181
  • 配置中心增加配置

ZooKeeper 使用下面的配置结构和环境(Environment)、应用(Application)、服务(Service)、版本(Version)、Tag对应, 配置级别优先级从低到高。

servicecomb:
  config:
    environment:  
      ${environment}:
        exampleText: exampleTextValue
        exampleYaml.yaml: exampleYamlValue
        exampleYaml.yml: exampleYamlValue
        exampleProperties.properties: examplePropertiesValue
    application:
      ${environment}:
        ${application}:
          exampleText: exampleTextValue
          exampleYaml.yaml: exampleYamlValue
          exampleYaml.yml: exampleYamlValue
          exampleProperties.properties: examplePropertiesValue
    service:
      ${environment}:
        ${application}:
          ${service}:
            exampleText: exampleTextValue
            exampleYaml.yaml: exampleYamlValue
            exampleYaml.yml: exampleYamlValue
            exampleProperties.properties: examplePropertiesValue
    version:
      ${environment}:
        ${application}:
          ${service}:
            ${version}:
              exampleText: exampleTextValue
              exampleYaml.yaml: exampleYamlValue
              exampleYaml.yml: exampleYamlValue
              exampleProperties.properties: examplePropertiesValue
    tag:
      ${environment}:
        ${application}:
          ${service}:
            ${tag}:
              exampleText: exampleTextValue
              exampleYaml.yaml: exampleYamlValue
              exampleYaml.yml: exampleYamlValue
              exampleProperties.properties: examplePropertiesValue
  • 配置项参考
配置项名 默认值 是否必须 含义
servicecomb.config.zk.connect-string 127.0.0.1:2181 ZooKeeper的地址信息,可以配置多个,用逗号分隔。
servicecomb.config.zk.authenticationSchema 认证方式,目前只能配置为 digest。
servicecomb.config.zk.authenticationInfo 当认证方式为 digest 的时候,配置用户名密码信息,比如: user:password
servicecomb.config.zk.connectionTimeoutMillis 1000 连接超时时间
servicecomb.config.zk.sessionTimeoutMillis 60000 会话超时时间