soul 网关(九):数据同步方式之 zookeeper(一)

前言

Soul 网关支持两种注册中心的同步,一种是前文中提到的 nacos,还有一种是今天要讲 Zookeeper。

zookeeper 的概要

ZooKeeper 是用于维护配置信息,命名,提供分布式同步以及提供组服务的集中式服务。官网上说了很多设计目标,很多都是在高可用性,和易用性这块;其实对于我们来说有一块内容是很重要的,那就是 watch 机制

watch 机制

ZooKeeper supports the concept of watches. Clients can set a watch on a znode. A watch will be triggered and removed when the znode changes. When a watch is triggered, the client receives a packet saying that the znode has changed. If the connection between the client and one of the ZooKeeper servers is broken, the client will receive a local notification.
New in 3.6.0: Clients can also set permanent, recursive watches on a znode that are not removed when triggered and that trigger for changes on the registered znode as well as any children znodes recursively.

以上是官网的原文,在这里我大致翻译一下:Zookeeper 支持 watches 机制, 客户端在 znode 上设置一个监听器,当 znode 变化时,监听器会被触发或者删除。 当监听器触发时,客户端会接受到到一个 znode 变化的包。 当客户端和某个 Zookeeper 服务端失去连接时, 客户端将会接受一个本地通知。

启动 Zookeeper

大概了解 Zookeeper 的基本概念之后,我们就可以简单的使用 Zookeeper 了。这里为了演示方式,直接从 zookeeper docker hub 中起了一个容器。

启动后

插句题外话,这个界面展示是因为本地装了 portainer, 有兴趣的可以移到它官网 进行了解。

启动之后,我们可以使用命令行的方式进行节点数据的查看,还可以通过 ZooInspecter 工具查看。

可以在 zooInspector下载

Soul zookeeper 的配置以及启动

admin 端配置

soul:
  sync:
      zookeeper:
          url: localhost:2181
          sessionTimeout: 5000
          connectionTimeout: 2000

bootstrap 端配置

  1. 检查 pom 文件是否引入包
        <!--soul data sync start use zookeeper-->
        <dependency>
            <groupId>org.dromara</groupId>
            <artifactId>soul-spring-boot-starter-sync-data-zookeeper</artifactId>
            <version>${project.version}</version>
        </dependency>
  1. yml 配置
soul :
    sync:
        zookeeper:
             url: localhost:2181
             sessionTimeout: 5000
             connectionTimeout: 2000
  1. 启动 admin,启动 bootstrap
    admin 显示
Started SoulAdminBootstrap in 19.743 seconds

bootstrap 显示

Started SoulBootstrapApplication in 7.27 seconds

即为显示成功

总结

  1. 今天讲了 Zookeeper 的概念,和 watch 机制。
  2. 怎么配置 Soul 中怎么配置 Zookeeper。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。