blob: f3f467ac6e6a055e671200fb2ba290b223185956 [file] [log] [blame]
<!doctype html><html lang=en class=no-js><head><meta name=ROBOTS content="INDEX, FOLLOW"><link rel=canonical href=https://cn.dubbo.apache.org/en/blog/2018/08/07/using-zookeeper-in-dubbo/><script>var _hmt=_hmt||[];(function(){var e,t=document.createElement("script");t.src="https://hm.baidu.com/hm.js?3b78f49ba47181e4d998a66b689446e9",e=document.getElementsByTagName("script")[0],e.parentNode.insertBefore(t,e)})()</script><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta http-equiv=Content-Security-Policy content="frame-src *"><meta name=generator content="Hugo 0.122.0"><link rel="shortcut icon" type=image/png href=/imgs/favicon.png><link rel=apple-touch-icon href=/favicons/apple-touch-icon-180x180.png sizes=180x180><link rel=manifest href=/manifest.webmanifest><title>Using Zookeeper in Dubbo | Apache Dubbo</title><meta property="og:title" content="Using Zookeeper in Dubbo">
<meta property="og:description" content="This article introduces basic concepts of Zookeeper, and how to use Zookeeper as a registry center.
"><meta property="og:type" content="article"><meta property="og:url" content="https://cn.dubbo.apache.org/en/blog/2018/08/07/using-zookeeper-in-dubbo/"><meta property="article:section" content="blog"><meta property="article:published_time" content="2018-08-07T00:00:00+00:00"><meta property="article:modified_time" content="2022-12-16T10:30:39+08:00"><meta itemprop=name content="Using Zookeeper in Dubbo"><meta itemprop=description content="This article introduces basic concepts of Zookeeper, and how to use Zookeeper as a registry center.
"><meta itemprop=datePublished content="2018-08-07T00:00:00+00:00"><meta itemprop=dateModified content="2022-12-16T10:30:39+08:00"><meta itemprop=wordCount content="1581"><meta itemprop=keywords content><meta name=twitter:card content="summary"><meta name=twitter:title content="Using Zookeeper in Dubbo"><meta name=twitter:description content="This article introduces basic concepts of Zookeeper, and how to use Zookeeper as a registry center.
"><script async src="https://www.googletagmanager.com/gtag/js?id=G-NM6FFMT51J"></script><script>var doNotTrack=!1;if(!doNotTrack){window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments)}gtag("js",new Date),gtag("config","G-NM6FFMT51J",{anonymize_ip:!1})}</script><link rel=preload href=/scss/main.min.f77e221bcdbe0cadb996060fe82063c747b60c229a1f8bbf0ee529adbadd84fa.css as=style><link href=/scss/main.min.f77e221bcdbe0cadb996060fe82063c747b60c229a1f8bbf0ee529adbadd84fa.css rel=stylesheet integrity><script src=/js/jquery-3.5.1.min.js integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin=anonymous></script><meta name=theme-color content="#326ce5"><link rel=stylesheet href=/css/feature-states.css><meta name=description content="This article introduces basic concepts of Zookeeper, and how to use Zookeeper as a registry center.
"><meta property="og:description" content="This article introduces basic concepts of Zookeeper, and how to use Zookeeper as a registry center.
"><meta name=twitter:description content="This article introduces basic concepts of Zookeeper, and how to use Zookeeper as a registry center.
"><meta property="og:url" content="https://cn.dubbo.apache.org/en/blog/2018/08/07/using-zookeeper-in-dubbo/"><meta property="og:title" content="Using Zookeeper in Dubbo"><meta name=twitter:title content="Using Zookeeper in Dubbo"><meta name=twitter:image:alt content="Apache Dubbo"><meta property="og:image" content="/imgs/blog/zk-emsemble.png"><meta property="og:type" content="article"><meta name=viewport content="width=device-width"><script async defer src=/js/github-buttons.js></script><link href=/css/community.css rel=stylesheet><link href=/css/contactus.css rel=stylesheet><link href=/css/language.css rel=stylesheet><script src=/js/script.js></script></head><body class="td-page td-documentation"><header><nav class="js-navbar-scroll navbar navbar-expand navbar-dark flex-column flex-md-row td-navbar" data-auto-burger=primary><a class=navbar-brand href=/en/><span class=navbar-logo></span><span class="text-uppercase font-weight-bold">Apache Dubbo</span></a><div class="td-navbar-nav-scroll ml-md-auto" id=main_navbar><ul class="navbar-nav mt-2 mt-lg-0"><li class="nav-item mr-4 mb-2 mb-lg-0"><a class=nav-link href=/en/overview/><span>Overview</span></a></li><li class="nav-item mr-4 mb-2 mb-lg-0"><a class=nav-link href=/en/docs3-v2/><span>SDK Manual</span></a></li><li class="nav-item mr-4 mb-2 mb-lg-0"><a class="nav-link active" href=/en/blog/><span class=active>Blog</span></a></li><li class="nav-item mr-4 mb-2 mb-lg-0"><a class=nav-link href=/en/download/><span>Download</span></a></li><li class="nav-item mr-4 mb-2 mb-lg-0"><a class=nav-link href=https://start.dubbo.apache.org/bootstrap.html target=_blank><span>Initializer</span><i class='fas fa-external-link-alt'></i></a></li><li class="nav-item dropdown d-lg-block"><a class="nav-link dropdown-toggle" href=# id=navbarDropdownMenuLink role=button data-toggle=dropdown aria-haspopup=true aria-expanded=false>English</a><div class="dropdown-menu dropdown-menu-right" aria-labelledby=navbarDropdownMenuLink><a class=dropdown-item href=/zh-cn/>中文</a></div></li><li class="nav-item dropdown d-lg-block"><div class="nav-item d-none d-lg-block"></div></li></ul></div></nav><section class="header-hero text-white pb-0 light-text"></section></header><div class="container-fluid td-outer"><div class=td-main><div class="row flex-md-nowrap"><div class="col-12 col-md-3 col-xl-2 td-sidebar d-print-none"><script>$(function(){$("#td-section-nav a").removeClass("active"),$("#td-section-nav #m-enblog20180807using-zookeeper-in-dubbo").addClass("active"),$("#td-section-nav #m-enblog20180807using-zookeeper-in-dubbo-li span").addClass("td-sidebar-nav-active-item"),$("#td-section-nav #m-enblog20180807using-zookeeper-in-dubbo").parents("li").addClass("active-path"),$("#td-section-nav li.active-path").addClass("show"),$("#td-section-nav li.active-path").children("input").prop("checked",!0),$("#td-section-nav #m-enblog20180807using-zookeeper-in-dubbo-li").siblings("li").addClass("show"),$("#td-section-nav #m-enblog20180807using-zookeeper-in-dubbo-li").children("ul").children("li").addClass("show"),$("#td-sidebar-menu").toggleClass("d-none")})</script><div id=td-sidebar-menu class="td-sidebar__inner d-none"><div id=content-mobile><form class="td-sidebar__search d-flex align-items-center"><button class="btn btn-link td-sidebar__toggle d-md-none p-0 ml-3 fas fa-bars" type=button data-toggle=collapse data-target=#td-section-nav aria-controls=td-docs-nav aria-expanded=false aria-label="Toggle section navigation"></button></form></div><div id=content-desktop></div><nav class="collapse td-sidebar-nav foldable-nav" id=td-section-nav><ul class="td-sidebar-nav__section pr-md-3 ul-0"><li class="td-sidebar-nav__section-title td-sidebar-nav__section with-child" id=m-enblog-li><ul class=ul-1><li class="td-sidebar-nav__section-title td-sidebar-nav__section with-child" id=m-enblognews-li><input type=checkbox id=m-enblognews-check>
<label for=m-enblognews-check><a href=/en/blog/news/ title="Articles About Apache Dubbo" class="align-left pl-0 td-sidebar-link td-sidebar-link__section" id=m-enblognews><span>Articles</span></a></label><ul class="ul-2 foldable"><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20240131tracing-dubbo-with-opentelemetry-li><input type=checkbox id=m-enblog20240131tracing-dubbo-with-opentelemetry-check>
<label for=m-enblog20240131tracing-dubbo-with-opentelemetry-check><a href=/en/blog/2024/01/31/tracing-dubbo-with-opentelemetry/ class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20240131tracing-dubbo-with-opentelemetry><span>Tracing Dubbo With OpenTelemetry</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20231023introduction-to-apache-dubbo-plugin-for-intellij-idea-li><input type=checkbox id=m-enblog20231023introduction-to-apache-dubbo-plugin-for-intellij-idea-check>
<label for=m-enblog20231023introduction-to-apache-dubbo-plugin-for-intellij-idea-check><a href=/en/blog/2023/10/23/introduction-to-apache-dubbo-plugin-for-intellij-idea/ class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20231023introduction-to-apache-dubbo-plugin-for-intellij-idea><span>Introduction to Apache Dubbo plugin for IntelliJ IDEA</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20230415advanced-cloud-native-dubbo-32-officially-released-li><input type=checkbox id=m-enblog20230415advanced-cloud-native-dubbo-32-officially-released-check>
<label for=m-enblog20230415advanced-cloud-native-dubbo-32-officially-released-check><a href=/en/blog/2023/04/15/advanced-cloud-native-dubbo-3.2-officially-released/ class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20230415advanced-cloud-native-dubbo-32-officially-released><span>Advanced cloud native - Dubbo 3.2 officially released</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20220504how-to-proxy-dubbo-service-in-apache-shenyu-gateway-li><input type=checkbox id=m-enblog20220504how-to-proxy-dubbo-service-in-apache-shenyu-gateway-check>
<label for=m-enblog20220504how-to-proxy-dubbo-service-in-apache-shenyu-gateway-check><a href=/en/blog/2022/05/04/how-to-proxy-dubbo-service-in-apache-shenyu-gateway/ class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20220504how-to-proxy-dubbo-service-in-apache-shenyu-gateway><span>How to proxy Dubbo service in Apache ShenYu Gateway</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20220118makes-it-more-convenient-for-you-to-proxy-dubbo-services-in-apache-apisix-li><input type=checkbox id=m-enblog20220118makes-it-more-convenient-for-you-to-proxy-dubbo-services-in-apache-apisix-check>
<label for=m-enblog20220118makes-it-more-convenient-for-you-to-proxy-dubbo-services-in-apache-apisix-check><a href=/en/blog/2022/01/18/makes-it-more-convenient-for-you-to-proxy-dubbo-services-in-apache-apisix/ class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20220118makes-it-more-convenient-for-you-to-proxy-dubbo-services-in-apache-apisix><span>Makes it More Convenient for You to Proxy Dubbo Services in Apache APISIX</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20190826service-test-li><input type=checkbox id=m-enblog20190826service-test-check>
<label for=m-enblog20190826service-test-check><a href=/en/blog/2019/08/26/service-test/ title="Dubbo Admin service test" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20190826service-test><span>Service test in dubbo admin</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20190811tracing-dubbo-service-with-apache-skywalking-li><input type=checkbox id=m-enblog20190811tracing-dubbo-service-with-apache-skywalking-check>
<label for=m-enblog20190811tracing-dubbo-service-with-apache-skywalking-check><a href=/en/blog/2019/08/11/tracing-dubbo-service-with-apache-skywalking/ title="Tracing Dubbo service with Apache Skywalking" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20190811tracing-dubbo-service-with-apache-skywalking><span>Use apache skywalking in dubbo</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20190502dubbo-extensible-mechanism-source-code-analysis-part-2-li><input type=checkbox id=m-enblog20190502dubbo-extensible-mechanism-source-code-analysis-part-2-check>
<label for=m-enblog20190502dubbo-extensible-mechanism-source-code-analysis-part-2-check><a href=/en/blog/2019/05/02/dubbo-extensible-mechanism-source-code-analysis-part-2/ title="Dubbo extensible mechanism source code analysis - part 2" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20190502dubbo-extensible-mechanism-source-code-analysis-part-2><span>Dubbo extensible mechanism - part 2</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20190425dubbo-extensible-mechanism-source-code-analysis-part-1-li><input type=checkbox id=m-enblog20190425dubbo-extensible-mechanism-source-code-analysis-part-1-check>
<label for=m-enblog20190425dubbo-extensible-mechanism-source-code-analysis-part-1-check><a href=/en/blog/2019/04/25/dubbo-extensible-mechanism-source-code-analysis-part-1/ title="Dubbo extensible mechanism source code analysis - part 1" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20190425dubbo-extensible-mechanism-source-code-analysis-part-1><span>Dubbo extensible mechanism - part 1</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20190220implementation-background-and-practice-of-dubbo-client-asynchronous-interface-li><input type=checkbox id=m-enblog20190220implementation-background-and-practice-of-dubbo-client-asynchronous-interface-check>
<label for=m-enblog20190220implementation-background-and-practice-of-dubbo-client-asynchronous-interface-check><a href=/en/blog/2019/02/20/implementation-background-and-practice-of-dubbo-client-asynchronous-interface/ title="Implementation background and practice of Dubbo client asynchronous interface" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20190220implementation-background-and-practice-of-dubbo-client-asynchronous-interface><span>Dubbo Async Client</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20190220implementation-background-and-practice-of-dubbo-server-asynchronous-interface-li><input type=checkbox id=m-enblog20190220implementation-background-and-practice-of-dubbo-server-asynchronous-interface-check>
<label for=m-enblog20190220implementation-background-and-practice-of-dubbo-server-asynchronous-interface-check><a href=/en/blog/2019/02/20/implementation-background-and-practice-of-dubbo-server-asynchronous-interface/ title="Implementation background and practice of Dubbo server asynchronous interface" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20190220implementation-background-and-practice-of-dubbo-server-asynchronous-interface><span>Dubbo Async Server</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20190117how-to-use-seata-to-ensure-consistency-between-dubbo-microservices-li><input type=checkbox id=m-enblog20190117how-to-use-seata-to-ensure-consistency-between-dubbo-microservices-check>
<label for=m-enblog20190117how-to-use-seata-to-ensure-consistency-between-dubbo-microservices-check><a href=/en/blog/2019/01/17/how-to-use-seata-to-ensure-consistency-between-dubbo-microservices/ title="How to use Seata to ensure consistency between Dubbo Microservices" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20190117how-to-use-seata-to-ensure-consistency-between-dubbo-microservices><span>Use Seata in Dubbo</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20181210the-fifth-dubbo-meetup-has-been-held-in-hangzhou-li><input type=checkbox id=m-enblog20181210the-fifth-dubbo-meetup-has-been-held-in-hangzhou-check>
<label for=m-enblog20181210the-fifth-dubbo-meetup-has-been-held-in-hangzhou-check><a href=/en/blog/2018/12/10/the-fifth-dubbo-meetup-has-been-held-in-hangzhou/ title="The fifth Dubbo meetup has been held in Hangzhou" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20181210the-fifth-dubbo-meetup-has-been-held-in-hangzhou><span>The fifth Dubbo meetup</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20181107dubbo-integrates-with-nacos-to-become-a-registry-li><input type=checkbox id=m-enblog20181107dubbo-integrates-with-nacos-to-become-a-registry-check>
<label for=m-enblog20181107dubbo-integrates-with-nacos-to-become-a-registry-check><a href=/en/blog/2018/11/07/dubbo-integrates-with-nacos-to-become-a-registry/ title="Dubbo Integrates with Nacos to Become a Registry" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20181107dubbo-integrates-with-nacos-to-become-a-registry><span>Use Dubbo with Nacos</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20181005introduction-to-the-dubbo-protocol-li><input type=checkbox id=m-enblog20181005introduction-to-the-dubbo-protocol-check>
<label for=m-enblog20181005introduction-to-the-dubbo-protocol-check><a href=/en/blog/2018/10/05/introduction-to-the-dubbo-protocol/ class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20181005introduction-to-the-dubbo-protocol><span>Introduction to the Dubbo protocol</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180930integrate-dubbo-with-kubernetes-li><input type=checkbox id=m-enblog20180930integrate-dubbo-with-kubernetes-check>
<label for=m-enblog20180930integrate-dubbo-with-kubernetes-check><a href=/en/blog/2018/09/30/integrate-dubbo-with-kubernetes/ class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180930integrate-dubbo-with-kubernetes><span>Integrate Dubbo with Kubernetes</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180902how-to-prepare-an-apache-release-li><input type=checkbox id=m-enblog20180902how-to-prepare-an-apache-release-check>
<label for=m-enblog20180902how-to-prepare-an-apache-release-check><a href=/en/blog/2018/09/02/how-to-prepare-an-apache-release/ class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180902how-to-prepare-an-apache-release><span>How to prepare an Apache Release</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180902how-to-implement-a-fully-asynchronous-calls-chain-based-on-dubbo-li><input type=checkbox id=m-enblog20180902how-to-implement-a-fully-asynchronous-calls-chain-based-on-dubbo-check>
<label for=m-enblog20180902how-to-implement-a-fully-asynchronous-calls-chain-based-on-dubbo-check><a href=/en/blog/2018/09/02/how-to-implement-a-fully-asynchronous-calls-chain-based-on-dubbo/ title="How to implement a fully asynchronous calls chain based on Dubbo" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180902how-to-implement-a-fully-asynchronous-calls-chain-based-on-dubbo><span>New Async Call</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180826the-fourth-dubbo-meetup-has-been-held-in-chengdu-li><input type=checkbox id=m-enblog20180826the-fourth-dubbo-meetup-has-been-held-in-chengdu-check>
<label for=m-enblog20180826the-fourth-dubbo-meetup-has-been-held-in-chengdu-check><a href=/en/blog/2018/08/26/the-fourth-dubbo-meetup-has-been-held-in-chengdu/ title="The fourth Dubbo meetup has been held in Chengdu" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180826the-fourth-dubbo-meetup-has-been-held-in-chengdu><span>The fourth Dubbo meetup</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180814dubbo-basic-usage-dubbo-consumer-configuration-li><input type=checkbox id=m-enblog20180814dubbo-basic-usage-dubbo-consumer-configuration-check>
<label for=m-enblog20180814dubbo-basic-usage-dubbo-consumer-configuration-check><a href=/en/blog/2018/08/14/dubbo-basic-usage-dubbo-consumer-configuration/ title=" Dubbo Basic Usage - Dubbo Consumer Configuration" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180814dubbo-basic-usage-dubbo-consumer-configuration><span>Dubbo Consumer Configuration</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180814dubbo-several-ways-about-synchronousasynchronous-invoke-li><input type=checkbox id=m-enblog20180814dubbo-several-ways-about-synchronousasynchronous-invoke-check>
<label for=m-enblog20180814dubbo-several-ways-about-synchronousasynchronous-invoke-check><a href=/en/blog/2018/08/14/dubbo-several-ways-about-synchronous/asynchronous-invoke/ title="Dubbo: Several ways about synchronous/asynchronous invoke" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180814dubbo-several-ways-about-synchronousasynchronous-invoke><span>Dubbo Invoke</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180814dubbo-basic-usage--dubbo-provider-configuration-li><input type=checkbox id=m-enblog20180814dubbo-basic-usage--dubbo-provider-configuration-check>
<label for=m-enblog20180814dubbo-basic-usage--dubbo-provider-configuration-check><a href=/en/blog/2018/08/14/dubbo-basic-usage--dubbo-provider-configuration/ title="Dubbo Basic Usage -- Dubbo Provider Configuration" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180814dubbo-basic-usage--dubbo-provider-configuration><span>Dubbo Provider Configuration</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180814manipulating-services-dynamically-via-qos-li><input type=checkbox id=m-enblog20180814manipulating-services-dynamically-via-qos-check>
<label for=m-enblog20180814manipulating-services-dynamically-via-qos-check><a href=/en/blog/2018/08/14/manipulating-services-dynamically-via-qos/ title="Manipulating Services Dynamically via QoS" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180814manipulating-services-dynamically-via-qos><span>Dubbo QoS Introduction</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180814source-code-analysis-of-spring-boot-dubbo-app-start-and-stop-li><input type=checkbox id=m-enblog20180814source-code-analysis-of-spring-boot-dubbo-app-start-and-stop-check>
<label for=m-enblog20180814source-code-analysis-of-spring-boot-dubbo-app-start-and-stop-check><a href=/en/blog/2018/08/14/source-code-analysis-of-spring-boot-dubbo-app-start-and-stop/ title="Source code analysis of spring-boot+Dubbo App start and stop" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180814source-code-analysis-of-spring-boot-dubbo-app-start-and-stop><span>Dubbo start/stop in spring boot</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180814implementation-of-cross-language-calls-by-dubbo2js-li><input type=checkbox id=m-enblog20180814implementation-of-cross-language-calls-by-dubbo2js-check>
<label for=m-enblog20180814implementation-of-cross-language-calls-by-dubbo2js-check><a href=/en/blog/2018/08/14/implementation-of-cross-language-calls-by-dubbo2.js/ title="Implementation of cross-language calls by Dubbo2.js" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180814implementation-of-cross-language-calls-by-dubbo2js><span>dubbo2.js introduction</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180814generic-invoke-of-dubbo-li><input type=checkbox id=m-enblog20180814generic-invoke-of-dubbo-check>
<label for=m-enblog20180814generic-invoke-of-dubbo-check><a href=/en/blog/2018/08/14/generic-invoke-of-dubbo/ title="Generic invoke of Dubbo" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180814generic-invoke-of-dubbo><span>Generic invoke</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180814native-image-using-graalvm-li><input type=checkbox id=m-enblog20180814native-image-using-graalvm-check>
<label for=m-enblog20180814native-image-using-graalvm-check><a href=/en/blog/2018/08/14/native-image-using-graalvm/ title="Native Image using GraalVM" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180814native-image-using-graalvm><span>Native Image</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180810dubbos-load-balance-li><input type=checkbox id=m-enblog20180810dubbos-load-balance-check>
<label for=m-enblog20180810dubbos-load-balance-check><a href=/en/blog/2018/08/10/dubbos-load-balance/ class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180810dubbos-load-balance><span>Dubbo's Load Balance</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180807use-annotations-in-dubbo-li><input type=checkbox id=m-enblog20180807use-annotations-in-dubbo-check>
<label for=m-enblog20180807use-annotations-in-dubbo-check><a href=/en/blog/2018/08/07/use-annotations-in-dubbo/ class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180807use-annotations-in-dubbo><span>Use Annotations In Dubbo</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180807using-zookeeper-in-dubbo-li><input type=checkbox id=m-enblog20180807using-zookeeper-in-dubbo-check>
<label for=m-enblog20180807using-zookeeper-in-dubbo-check><a href=/en/blog/2018/08/07/using-zookeeper-in-dubbo/ class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180807using-zookeeper-in-dubbo><span>Using Zookeeper in Dubbo</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180807dubbo-101-li><input type=checkbox id=m-enblog20180807dubbo-101-check>
<label for=m-enblog20180807dubbo-101-check><a href=/en/blog/2018/08/07/dubbo-101/ class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180807dubbo-101><span>Your First Dubbo Demo</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180730the-third-dubbo-meetup-has-been-held-in-shenzhen-li><input type=checkbox id=m-enblog20180730the-third-dubbo-meetup-has-been-held-in-shenzhen-check>
<label for=m-enblog20180730the-third-dubbo-meetup-has-been-held-in-shenzhen-check><a href=/en/blog/2018/07/30/the-third-dubbo-meetup-has-been-held-in-shenzhen/ title="The third Dubbo meetup has been held in Shenzhen" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180730the-third-dubbo-meetup-has-been-held-in-shenzhen><span>The third Dubbo meetup</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180727sentinel-the-flow-sentinel-of-dubbo-services-li><input type=checkbox id=m-enblog20180727sentinel-the-flow-sentinel-of-dubbo-services-check>
<label for=m-enblog20180727sentinel-the-flow-sentinel-of-dubbo-services-check><a href=/en/blog/2018/07/27/sentinel-the-flow-sentinel-of-dubbo-services/ title="Sentinel: The flow sentinel of Dubbo services" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180727sentinel-the-flow-sentinel-of-dubbo-services><span>Introduce sentinel</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180712tracking-with-pinpoint-li><input type=checkbox id=m-enblog20180712tracking-with-pinpoint-check>
<label for=m-enblog20180712tracking-with-pinpoint-check><a href=/en/blog/2018/07/12/tracking-with-pinpoint/ class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180712tracking-with-pinpoint><span>Tracking with Pinpoint</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180701your-first-dubbo-filter-li><input type=checkbox id=m-enblog20180701your-first-dubbo-filter-check>
<label for=m-enblog20180701your-first-dubbo-filter-check><a href=/en/blog/2018/07/01/your-first-dubbo-filter/ class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180701your-first-dubbo-filter><span>Your First Dubbo Filter</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180623the-second-dubbo-shanghai-meetup-has-been-held-successfully-li><input type=checkbox id=m-enblog20180623the-second-dubbo-shanghai-meetup-has-been-held-successfully-check>
<label for=m-enblog20180623the-second-dubbo-shanghai-meetup-has-been-held-successfully-check><a href=/en/blog/2018/06/23/the-second-dubbo-shanghai-meetup-has-been-held-successfully/ title="The second Dubbo Shanghai meetup has been held successfully" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180623the-second-dubbo-shanghai-meetup-has-been-held-successfully><span>The second Dubbo meetup</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180512the-first-dubbo-meetup-has-been-held-in-beijing-li><input type=checkbox id=m-enblog20180512the-first-dubbo-meetup-has-been-held-in-beijing-check>
<label for=m-enblog20180512the-first-dubbo-meetup-has-been-held-in-beijing-check><a href=/en/blog/2018/05/12/the-first-dubbo-meetup-has-been-held-in-beijing/ title="The first Dubbo meetup has been held in Beijing" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180512the-first-dubbo-meetup-has-been-held-in-beijing><span>The first Dubbo meetup</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180502the-apachecon-na-schedule-has-been-announced-li><input type=checkbox id=m-enblog20180502the-apachecon-na-schedule-has-been-announced-check>
<label for=m-enblog20180502the-apachecon-na-schedule-has-been-announced-check><a href=/en/blog/2018/05/02/the-apachecon-na-schedule-has-been-announced/ title="The ApacheCon NA schedule has been announced" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180502the-apachecon-na-schedule-has-been-announced><span>ApacheCon NA</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180425the-gsocgoogle-summer-of-code-2018-li><input type=checkbox id=m-enblog20180425the-gsocgoogle-summer-of-code-2018-check>
<label for=m-enblog20180425the-gsocgoogle-summer-of-code-2018-check><a href=/en/blog/2018/04/25/the-gsocgoogle-summer-of-code-2018/ title="The GSoC(Google Summer of Code) 2018" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180425the-gsocgoogle-summer-of-code-2018><span>GSoC 2018</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20180422dubbo-roadmap-is-announced-in-qcon-beijing-2018-li><input type=checkbox id=m-enblog20180422dubbo-roadmap-is-announced-in-qcon-beijing-2018-check>
<label for=m-enblog20180422dubbo-roadmap-is-announced-in-qcon-beijing-2018-check><a href=/en/blog/2018/04/22/dubbo-roadmap-is-announced-in-qcon-beijing-2018/ title="Dubbo roadmap is announced in QCon Beijing 2018" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20180422dubbo-roadmap-is-announced-in-qcon-beijing-2018><span>QCon Beijing 2018</span></a></label></li></ul></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section with-child" id=m-enblogproposals-li><input type=checkbox id=m-enblogproposals-check>
<label for=m-enblogproposals-check><a href=/en/blog/proposals/ title="Proposals About Apache Dubbo" class="align-left pl-0 td-sidebar-link td-sidebar-link__section" id=m-enblogproposals><span>Proposals</span></a></label><ul class="ul-2 foldable"><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog10101application-level-service-discovery-li><input type=checkbox id=m-enblog10101application-level-service-discovery-check>
<label for=m-enblog10101application-level-service-discovery-check><a href=/en/blog/1/01/01/application-level-service-discovery/ class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog10101application-level-service-discovery><span>Application-Level Service Discovery</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog10101enhanced-http-standard-capabilities-of-triple-protocol-li><input type=checkbox id=m-enblog10101enhanced-http-standard-capabilities-of-triple-protocol-check>
<label for=m-enblog10101enhanced-http-standard-capabilities-of-triple-protocol-check><a href=/en/blog/1/01/01/enhanced-http-standard-capabilities-of-triple-protocol/ class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog10101enhanced-http-standard-capabilities-of-triple-protocol><span>Enhanced HTTP Standard Capabilities of Triple Protocol</span></a></label></li></ul></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section with-child" id=m-enblogreleases-li><input type=checkbox id=m-enblogreleases-check>
<label for=m-enblogreleases-check><a href=/en/blog/releases/ title="New Releases" class="align-left pl-0 td-sidebar-link td-sidebar-link__section" id=m-enblogreleases><span>Releases</span></a></label><ul class="ul-2 foldable"><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog202109202714-release-note-li><input type=checkbox id=m-enblog202109202714-release-note-check>
<label for=m-enblog202109202714-release-note-check><a href=/en/blog/2021/09/20/2.7.14-release-note/ title="2.7.14 Release Note" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog202109202714-release-note><span>2.7.14</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog202108233021-release-note-li><input type=checkbox id=m-enblog202108233021-release-note-check>
<label for=m-enblog202108233021-release-note-check><a href=/en/blog/2021/08/23/3.0.2.1-release-note/ title="3.0.2.1 Release Note" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog202108233021-release-note><span>3.0.2.1</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20210818302-release-note-li><input type=checkbox id=m-enblog20210818302-release-note-check>
<label for=m-enblog20210818302-release-note-check><a href=/en/blog/2021/08/18/3.0.2-release-note/ title="3.0.2 Release Note" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20210818302-release-note><span>3.0.2</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20210702301-release-note-li><input type=checkbox id=m-enblog20210702301-release-note-check>
<label for=m-enblog20210702301-release-note-check><a href=/en/blog/2021/07/02/3.0.1-release-note/ title="3.0.1 Release Note" class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20210702301-release-note><span>3.0.1</span></a></label></li><li class="td-sidebar-nav__section-title td-sidebar-nav__section without-child" id=m-enblog20200518past-releases-li><input type=checkbox id=m-enblog20200518past-releases-check>
<label for=m-enblog20200518past-releases-check><a href=/en/blog/2020/05/18/past-releases/ class="align-left pl-0 td-sidebar-link td-sidebar-link__page" id=m-enblog20200518past-releases><span>Past Releases</span></a></label></li></ul></li></ul></li></ul></nav></div></div><main class="col-12 col-md-9 col-xl-8 pl-md-5" role=main><nav aria-label=breadcrumb class=td-breadcrumbs><ol class=breadcrumb><li class=breadcrumb-item><a href=https://cn.dubbo.apache.org/en/blog/>Blog</a></li><li class=breadcrumb-item><a href=https://cn.dubbo.apache.org/en/blog/news/>Articles</a></li><li class="breadcrumb-item active" aria-current=page><a href=https://cn.dubbo.apache.org/en/blog/2018/08/07/using-zookeeper-in-dubbo/ aria-disabled=true class="btn-link disabled">Using Zookeeper in Dubbo</a></li></ol></nav><section id=deprecation-warning><div class="content deprecation-warning pageinfo outdated-blog"><p>This article is more than one year old. Older articles may contain outdated content. Check that the information in the page has not become incorrect since its publication.</p></div></section><div class=td-content><h1>Using Zookeeper in Dubbo</h1><div class=lead>This article introduces basic concepts of Zookeeper, and how to use Zookeeper as a registry center.</div><div class="td-byline mb-4"><time datetime=2018-08-07 class=text-muted>Tuesday, August 07, 2018</time></div><header class=article-meta></header><h2 id=introduction-of-zookeeper>Introduction of Zookeeper</h2><h3 id=the-basic-concept>The basic concept</h3><p>In the mordern distrbuted applications, there are multiple coordination problems between nodes and nodes, including: leader election, group service, locking, configuration management, naming and synchronization. Apache Zookeeper, as its name implied, is a distributed, open-source coordination service framwork to address these demand.</p><p>In order to ensure the high performance, highly available and strictly ordered access, the performance aspects of ZooKeeper means it can be used in large, distributed systems and can also be deployed in cluster mode, which called &lsquo;ZooKeeper ensemble&rsquo;. In ZooKeeper ensemble, all write requests from clients are forwarded to a single server, called the leader, through the ZAB(Zookeeper Atomic Broadcast Protocol) to make sure the message in each nodes are same. Clients can access any one of the clusters to read and write data without worrying about inconsistencies in the data.</p><p><img src=/imgs/blog/zk-emsemble.png alt="Diagram shows client-server architecture of ZooKeeper">
<em>Image Credit : ebook -Zookeeper-Distributed Process Coordination from O&rsquo;Reilly</em></p><p>The method to store the data in Zookeeper is similar as the standard UNIX file system, as a data model styled after the familiar directory tree structure of file systems. When we talking about ZooKeeper data nodes, we call it Znodes to clarify it.</p><p><img src=/imgs/blog/zk-tree.png alt=zk-tree>
<em>Image Credit : ebook -Zookeeper-Distributed Process Coordination from O&rsquo;Reilly</em></p><h3 id=basic-implementation>Basic Implementation</h3><p>You could donwload and install Zookeeper directly<sup id=fnref:1><a href=#fn:1 class=footnote-ref role=doc-noteref>1</a></sup>.
Or you could use Homebrew <sup id=fnref:2><a href=#fn:2 class=footnote-ref role=doc-noteref>2</a></sup> <code>brew install zookeeper</code> to install Zookeeper in Mac OS.
Considering the versatility, we run the Zookeeper by using docker in this blog. If you have not installed the docker yet, please prepare the docker environment first. <sup id=fnref:3><a href=#fn:3 class=footnote-ref role=doc-noteref>3</a></sup></p><h4 id=1-running-the-zookeeper>1. Running the Zookeeper</h4><p>Execute the command to run zookeeper in a docker container</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-shell data-lang=shell><span style=display:flex><span>docker run --rm --name zookeeper -p 2181:2181 zookeeper
</span></span></code></pre></div><h4 id=2-entering-the-zookeeper-container>2. Entering the zookeeper container</h4><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-shell data-lang=shell><span style=display:flex><span>docker <span style=color:#b58900>exec</span> -it zookeeper bash
</span></span></code></pre></div><p>In the <code>bin</code> directory, there is a command to start zookeeper <code>zkServer</code> and the Management Console <code>zkCli</code></p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-shell data-lang=shell><span style=display:flex><span>bash-4.4# ls -l bin
</span></span><span style=display:flex><span>total <span style=color:#2aa198>36</span>
</span></span><span style=display:flex><span>-rwxr-xr-x <span style=color:#2aa198>1</span> zookeepe zookeepe <span style=color:#2aa198>232</span> Mar <span style=color:#2aa198>27</span> 04:32 README.txt
</span></span><span style=display:flex><span>-rwxr-xr-x <span style=color:#2aa198>1</span> zookeepe zookeepe <span style=color:#2aa198>1937</span> Mar <span style=color:#2aa198>27</span> 04:32 zkCleanup.sh
</span></span><span style=display:flex><span>-rwxr-xr-x <span style=color:#2aa198>1</span> zookeepe zookeepe <span style=color:#2aa198>1056</span> Mar <span style=color:#2aa198>27</span> 04:32 zkCli.cmd
</span></span><span style=display:flex><span>-rwxr-xr-x <span style=color:#2aa198>1</span> zookeepe zookeepe <span style=color:#2aa198>1534</span> Mar <span style=color:#2aa198>27</span> 04:32 zkCli.sh
</span></span><span style=display:flex><span>-rwxr-xr-x <span style=color:#2aa198>1</span> zookeepe zookeepe <span style=color:#2aa198>1759</span> Mar <span style=color:#2aa198>27</span> 04:32 zkEnv.cmd
</span></span><span style=display:flex><span>-rwxr-xr-x <span style=color:#2aa198>1</span> zookeepe zookeepe <span style=color:#2aa198>2696</span> Mar <span style=color:#2aa198>27</span> 04:32 zkEnv.sh
</span></span><span style=display:flex><span>-rwxr-xr-x <span style=color:#2aa198>1</span> zookeepe zookeepe <span style=color:#2aa198>1089</span> Mar <span style=color:#2aa198>27</span> 04:32 zkServer.cmd
</span></span><span style=display:flex><span>-rwxr-xr-x <span style=color:#2aa198>1</span> zookeepe zookeepe <span style=color:#2aa198>6773</span> Mar <span style=color:#2aa198>27</span> 04:32 zkServer.sh
</span></span></code></pre></div><h4 id=3-entering-the-zookeeper-management-interface-via-zkcli>3. Entering the zookeeper management interface via zkCli</h4><p>Since it was started through docker, the process of Zookeeper has been started and will provide the services to the public via port 2181.</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-shell data-lang=shell><span style=display:flex><span>bash-4.4# ps
</span></span><span style=display:flex><span>PID USER TIME COMMAND
</span></span><span style=display:flex><span> <span style=color:#2aa198>1</span> zookeepe 0:02 /usr/lib/jvm/java-1.8-openjdk/jre/bin/java -Dzookeeper.log.dir<span style=color:#719e07>=</span>. -Dzookeeper.root
</span></span><span style=display:flex><span> <span style=color:#2aa198>32</span> root 0:00 bash
</span></span><span style=display:flex><span> <span style=color:#2aa198>42</span> root 0:00 ps
</span></span></code></pre></div><p>So, it allows you to access Zookeeper&rsquo;s console directly through <code>zkCli </code>for management.</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-shell data-lang=shell><span style=display:flex><span>bash-4.4# bin/zkCli.sh -server 127.0.0.1:2181
</span></span><span style=display:flex><span>Connecting to 127.0.0.1:2181
</span></span><span style=display:flex><span>...
</span></span><span style=display:flex><span>WATCHER::
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span>WatchedEvent state:SyncConnected type:None path:null
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span><span style=color:#719e07>[</span>zk: 127.0.0.1:2181<span style=color:#719e07>(</span>CONNECTED<span style=color:#719e07>)</span> 0<span style=color:#719e07>]</span> <span style=color:#b58900>help</span>
</span></span><span style=display:flex><span>ZooKeeper -server host:port cmd args
</span></span><span style=display:flex><span> stat path <span style=color:#719e07>[</span>watch<span style=color:#719e07>]</span>
</span></span><span style=display:flex><span> <span style=color:#b58900>set</span> path data <span style=color:#719e07>[</span>version<span style=color:#719e07>]</span>
</span></span><span style=display:flex><span> ls path <span style=color:#719e07>[</span>watch<span style=color:#719e07>]</span>
</span></span><span style=display:flex><span> delquota <span style=color:#719e07>[</span>-n|-b<span style=color:#719e07>]</span> path
</span></span><span style=display:flex><span> ls2 path <span style=color:#719e07>[</span>watch<span style=color:#719e07>]</span>
</span></span><span style=display:flex><span> setAcl path acl
</span></span><span style=display:flex><span> setquota -n|-b val path
</span></span><span style=display:flex><span> <span style=color:#b58900>history</span>
</span></span><span style=display:flex><span> redo cmdno
</span></span><span style=display:flex><span> printwatches on|off
</span></span><span style=display:flex><span> delete path <span style=color:#719e07>[</span>version<span style=color:#719e07>]</span>
</span></span><span style=display:flex><span> sync path
</span></span><span style=display:flex><span> listquota path
</span></span><span style=display:flex><span> rmr path
</span></span><span style=display:flex><span> get path <span style=color:#719e07>[</span>watch<span style=color:#719e07>]</span>
</span></span><span style=display:flex><span> create <span style=color:#719e07>[</span>-s<span style=color:#719e07>]</span> <span style=color:#719e07>[</span>-e<span style=color:#719e07>]</span> path data acl
</span></span><span style=display:flex><span> addauth scheme auth
</span></span><span style=display:flex><span> quit
</span></span><span style=display:flex><span> getAcl path
</span></span><span style=display:flex><span> close
</span></span><span style=display:flex><span> connect host:port
</span></span></code></pre></div><h4 id=4-basic-examples-on-zkcli>4. Basic Examples on zkCli</h4><p>Create <code>/hello-zone</code> node:</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-shell data-lang=shell><span style=display:flex><span><span style=color:#719e07>[</span>zk: 127.0.0.1:2181<span style=color:#719e07>(</span>CONNECTED<span style=color:#719e07>)</span> 19<span style=color:#719e07>]</span> create /hello-zone <span style=color:#2aa198>&#39;world&#39;</span>
</span></span><span style=display:flex><span>Created /hello-zone
</span></span></code></pre></div><p>List the child nodes under <code>/</code> and confirm that <code>hello-zone</code> is created:</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-shell data-lang=shell><span style=display:flex><span><span style=color:#719e07>[</span>zk: 127.0.0.1:2181<span style=color:#719e07>(</span>CONNECTED<span style=color:#719e07>)</span> 20<span style=color:#719e07>]</span> ls /
</span></span><span style=display:flex><span><span style=color:#719e07>[</span>zookeeper, hello-zone<span style=color:#719e07>]</span>
</span></span></code></pre></div><p>List the child nodes for <code>/hello-zone</code> and verify that it is empty:</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-shell data-lang=shell><span style=display:flex><span><span style=color:#719e07>[</span>zk: 127.0.0.1:2181<span style=color:#719e07>(</span>CONNECTED<span style=color:#719e07>)</span> 21<span style=color:#719e07>]</span> ls /hello-zone
</span></span><span style=display:flex><span><span style=color:#719e07>[]</span>
</span></span></code></pre></div><p>Get the data stored on the <code>/hello-zone</code> node:</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-shell data-lang=shell><span style=display:flex><span><span style=color:#719e07>[</span>zk: 127.0.0.1:2181<span style=color:#719e07>(</span>CONNECTED<span style=color:#719e07>)</span> 22<span style=color:#719e07>]</span> get /hello-zone
</span></span><span style=display:flex><span>world
</span></span></code></pre></div><h2 id=using-zookeeper-in-dubbo>Using Zookeeper in Dubbo</h2><p>Zookeeper is used for service registration discovery and configuration management in Dubbo, and the structure of data in Zookeeper is shown in the following figure:</p><p><img src=/imgs/blog/dubbo-in-zk.jpg alt=dubbo-in-zk></p><p>First, all data related to Dubbo is organized under the root node of <code>/dubbo</code>.</p><p>The secondary directory is the service name like <code>com.foo.BarService</code>.</p><p>The three-level directory has two child nodes, <code>providers</code> and <code>consumers</code>, representing the supplier and customers of the service.</p><p>The URL information for each application instance associated with the service will be recorded by the Level 4 directory. The <code>providers</code> and <code>consumer</code> will stored the providers information and the consumers information of the services seperately.<br>For example, the service provider of <code>com.foo.BarService</code> will register its URL Information to <code>/dubbo/com.foo.BarService/providers</code>; Similarly, service consumers will register their information under the corresponding <code>consumer</code> node. At the same time, consumers will subscribe to the corresponding <code>providers</code> node to be able to detect the changes of the service provider address list.</p><h3 id=prepare-the-sample-code>Prepare the sample code</h3><p>The code in this document can be found in <a href=https://github.com/dubbo/dubbo-samples/tree/master/3-extensions/registry/dubbo-samples-zookeeper>https://github.com/dubbo/dubbo-samples/tree/master/3-extensions/registry/dubbo-samples-zookeeper</a>.</p><h4 id=1-interface-definition>1. Interface definition</h4><p>Define a simple <code>greetingservice</code> interface with only one simple method named <code>sayHello</code> to greet to the caller.</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-java data-lang=java><span style=display:flex><span><span style=color:#268bd2>public</span> <span style=color:#268bd2>interface</span> <span style=color:#268bd2>GreetingService</span> {
</span></span><span style=display:flex><span> String <span style=color:#268bd2>sayHello</span>(String name);
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><h4 id=2-server-implementation>2. Server: Implementation</h4><p>Implement the <code>GreetingService</code> interface and mark it as a service for Dubbo via <code>@Service</code>.</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-java data-lang=java><span style=display:flex><span><span style=color:#268bd2>@Service</span>
</span></span><span style=display:flex><span><span style=color:#268bd2>public</span> <span style=color:#268bd2>class</span> <span style=color:#268bd2>AnnotatedGreetingService</span> <span style=color:#268bd2>implements</span> GreetingService {
</span></span><span style=display:flex><span> <span style=color:#268bd2>public</span> String <span style=color:#268bd2>sayHello</span>(String name) {
</span></span><span style=display:flex><span> <span style=color:#719e07>return</span> <span style=color:#2aa198>&#34;hello, &#34;</span> <span style=color:#719e07>+</span> name;
</span></span><span style=display:flex><span> }
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><h4 id=3-server-assembly>3. Server: Assembly</h4><p>Define ProviderConfiguration to assemble Dubbo services.</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-java data-lang=java><span style=display:flex><span><span style=color:#268bd2>@Configuration</span>
</span></span><span style=display:flex><span><span style=color:#268bd2>@EnableDubbo</span>(scanBasePackages <span style=color:#719e07>=</span> <span style=color:#2aa198>&#34;com.alibaba.dubbo.samples.impl&#34;</span>)
</span></span><span style=display:flex><span><span style=color:#268bd2>@PropertySource</span>(<span style=color:#2aa198>&#34;classpath:/spring/dubbo-provider.properties&#34;</span>)
</span></span><span style=display:flex><span><span style=color:#268bd2>static</span> <span style=color:#268bd2>class</span> <span style=color:#268bd2>ProviderConfiguration</span> {}
</span></span></code></pre></div><p>Dubbo-provider.properties is an external configuration in a spring application, as follows:</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-properties data-lang=properties><span style=display:flex><span>dubbo.application.name<span style=color:#719e07>=</span><span style=color:#2aa198>demo-provider</span>
</span></span><span style=display:flex><span>dubbo.registry.address<span style=color:#719e07>=</span><span style=color:#2aa198>zookeeper://$DOCKER_HOST:2181</span>
</span></span><span style=display:flex><span>dubbo.protocol.name<span style=color:#719e07>=</span><span style=color:#2aa198>dubbo</span>
</span></span><span style=display:flex><span>dubbo.protocol.port<span style=color:#719e07>=</span><span style=color:#2aa198>20880</span>
</span></span></code></pre></div><p>Since zookeeper runs in a docker container, please be noted that:</p><ul><li>We assumes that Dubbo applications is running on the host machine (outside the docker container) in this document, and needs to replace the PATH of Zookeeper with the IP address of the Environment Variable <em>${DOCKER_HOST}</em>. Please find more detail in the official Docker documentation.</li><li>When the Dubbo application is a docker application, the container&rsquo;s name is equivalent to Zookeeper&rsquo;s. The container&rsquo;s name is ** zookeeper ** in this document.</li><li>Of course, if you don&rsquo;t want to run the Zookeeper in a container mode, just simply replace <em>$DOCKER_HOST</em> with <strong>localhost</strong>.</li></ul><h4 id=4-server-starting-service>4. Server: Starting Service</h4><p>In the <code>main</code> method, you could provide the Dubbo service by running a Spring Context.</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-java data-lang=java><span style=display:flex><span><span style=color:#268bd2>public</span> <span style=color:#268bd2>class</span> <span style=color:#268bd2>ProviderBootstrap</span> {
</span></span><span style=display:flex><span> <span style=color:#268bd2>public</span> <span style=color:#268bd2>static</span> <span style=color:#dc322f>void</span> <span style=color:#268bd2>main</span>(String<span style=color:#719e07>[]</span> args) <span style=color:#268bd2>throws</span> Exception {
</span></span><span style=display:flex><span> AnnotationConfigApplicationContext context <span style=color:#719e07>=</span> <span style=color:#719e07>new</span> AnnotationConfigApplicationContext(ProviderConfiguration.class);
</span></span><span style=display:flex><span> context.start();
</span></span><span style=display:flex><span> System.in.read();
</span></span><span style=display:flex><span> }
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>Start the <code>main</code> method of server, you will get the following output, which represents the success of the server&rsquo;s startup, and the <code>GreetingService</code> service is registered on the ZookeeperRegistry:</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-sh data-lang=sh><span style=display:flex><span><span style=color:#719e07>[</span>03/08/18 10:50:33:033 CST<span style=color:#719e07>]</span> main INFO zookeeper.ZookeeperRegistry: <span style=color:#719e07>[</span>DUBBO<span style=color:#719e07>]</span> Register: dubbo://192.168.99.1:20880/com.alibaba.dubbo.samples.api.GreetingService?anyhost<span style=color:#719e07>=</span>true&amp;<span style=color:#268bd2>application</span><span style=color:#719e07>=</span>demo-provider&amp;<span style=color:#268bd2>dubbo</span><span style=color:#719e07>=</span>2.6.2&amp;<span style=color:#268bd2>generic</span><span style=color:#719e07>=</span>false&amp;<span style=color:#268bd2>interface</span><span style=color:#719e07>=</span>com.alibaba.dubbo.samples.api.GreetingService&amp;<span style=color:#268bd2>methods</span><span style=color:#719e07>=</span>sayHello&amp;<span style=color:#268bd2>pid</span><span style=color:#719e07>=</span>12938&amp;<span style=color:#268bd2>side</span><span style=color:#719e07>=</span>provider&amp;<span style=color:#268bd2>timestamp</span><span style=color:#719e07>=</span>1533264631849, dubbo version: 2.6.2, current host: 192.168.99.1
</span></span></code></pre></div><p>You could find the registration information of the service provider through the Zookeeper management terminal:</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-sh data-lang=sh><span style=display:flex><span>$ docker <span style=color:#b58900>exec</span> -it zookeeper bash
</span></span><span style=display:flex><span>bash-4.4# bin/zkCli.sh -server localhost:218
</span></span><span style=display:flex><span>Connecting to localhost:2181
</span></span><span style=display:flex><span>...
</span></span><span style=display:flex><span>Welcome to ZooKeeper!
</span></span><span style=display:flex><span>JLine support is enabled
</span></span><span style=display:flex><span>...
</span></span><span style=display:flex><span><span style=color:#719e07>[</span>zk: localhost:2181<span style=color:#719e07>(</span>CONNECTED<span style=color:#719e07>)</span> 0<span style=color:#719e07>]</span> ls /dubbo/com.alibaba.dubbo.samples.api.GreetingService/providers
</span></span><span style=display:flex><span><span style=color:#719e07>[</span>dubbo%3A%2F%2F192.168.99.1%3A20880%2Fcom.alibaba.dubbo.samples.api.GreetingService%3Fanyhost%3Dtrue%26application%3Ddemo-provider%26dubbo%3D2.6.2%26generic%3Dfalse%26interface%3Dcom.alibaba.dubbo.samples.api.GreetingService%26methods%3DsayHello%26pid%3D12938%26side%3Dprovider%26timestamp%3D1533264631849<span style=color:#719e07>]</span>
</span></span></code></pre></div><p>You could find that the Dubbo services just registered its URL address at the <code>providers</code> node as follows:
<em>dubbo://192.168.99.1:20880/com.alibaba.dubbo.samples.api.GreetingService?anyhost=true&amp;application=demo-provider&amp;dubbo=2.6.2&amp;generic=false&amp;interface=com.alibaba.dubbo.samples.api.GreetingService&amp;methods=sayHello&amp;pid=12938&amp;side=provider&amp;timestamp=1533264631849</em></p><h4 id=5-client-reference-service>5. Client: Reference Service</h4><p>You could declare the reference service by @Reference, while it will generate a full call. The target address of the service could be queried by the Zookeeper&rsquo;s <code>provider</code> node.</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-java data-lang=java><span style=display:flex><span><span style=color:#268bd2>@Component</span>(<span style=color:#2aa198>&#34;annotatedConsumer&#34;</span>)
</span></span><span style=display:flex><span><span style=color:#268bd2>public</span> <span style=color:#268bd2>class</span> <span style=color:#268bd2>GreetingServiceConsumer</span> {
</span></span><span style=display:flex><span> <span style=color:#268bd2>@Reference</span>
</span></span><span style=display:flex><span> <span style=color:#268bd2>private</span> GreetingService greetingService;
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span> <span style=color:#268bd2>public</span> String <span style=color:#268bd2>doSayHello</span>(String name) {
</span></span><span style=display:flex><span> <span style=color:#719e07>return</span> greetingService.sayHello(name);
</span></span><span style=display:flex><span> }
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><h4 id=6-client-assembling>6. Client: Assembling</h4><p>Define the ConsumerConfiguration to assemble Dubbo service.</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-java data-lang=java><span style=display:flex><span><span style=color:#268bd2>@Configuration</span>
</span></span><span style=display:flex><span><span style=color:#268bd2>@EnableDubbo</span>(scanBasePackages <span style=color:#719e07>=</span> <span style=color:#2aa198>&#34;com.alibaba.dubbo.samples.action&#34;</span>)
</span></span><span style=display:flex><span><span style=color:#268bd2>@PropertySource</span>(<span style=color:#2aa198>&#34;classpath:/spring/dubbo-consumer.properties&#34;</span>)
</span></span><span style=display:flex><span><span style=color:#268bd2>@ComponentScan</span>(value <span style=color:#719e07>=</span> {<span style=color:#2aa198>&#34;com.alibaba.dubbo.samples.action&#34;</span>})
</span></span><span style=display:flex><span><span style=color:#268bd2>static</span> <span style=color:#268bd2>class</span> <span style=color:#268bd2>ConsumerConfiguration</span> {}
</span></span></code></pre></div><p>&ldquo;dubbo-consumer.properties&rdquo; is a method of external configuration in a Spring application, as follows:</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-properties data-lang=properties><span style=display:flex><span>dubbo.application.name<span style=color:#719e07>=</span><span style=color:#2aa198>demo-consumer</span>
</span></span><span style=display:flex><span>dubbo.registry.address<span style=color:#719e07>=</span><span style=color:#2aa198>zookeeper://$DOCKER_HOST:2181</span>
</span></span><span style=display:flex><span>dubbo.consumer.timeout<span style=color:#719e07>=</span><span style=color:#2aa198>3000</span>
</span></span></code></pre></div><p>Same as <strong>3. Server: Assembling</strong>, You need to modify <em>$DOCKER_HOST</em> defined in <em>dubbo.registry.address</em> according to your own environment. You could find more instructions in step 3.</p><h4 id=7-client-initiating-a-remote-call>7. Client: Initiating A Remote Call</h4><p>Run <code>main</code> to initiate a remote call from a existed service provider. Dubbo first subscribes to the zookeeper service address and then selects one from the list of returned addresses to invoke the client:</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-java data-lang=java><span style=display:flex><span><span style=color:#268bd2>public</span> <span style=color:#268bd2>class</span> <span style=color:#268bd2>ConsumerBootstrap</span> {
</span></span><span style=display:flex><span> <span style=color:#268bd2>public</span> <span style=color:#268bd2>static</span> <span style=color:#dc322f>void</span> <span style=color:#268bd2>main</span>(String<span style=color:#719e07>[]</span> args) {
</span></span><span style=display:flex><span><span style=color:#268bd2>public</span> <span style=color:#268bd2>class</span> <span style=color:#268bd2>ConsumerBootstrap</span> {
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span> <span style=color:#268bd2>public</span> <span style=color:#268bd2>static</span> <span style=color:#dc322f>void</span> <span style=color:#268bd2>main</span>(String<span style=color:#719e07>[]</span> args) <span style=color:#268bd2>throws</span> IOException {
</span></span><span style=display:flex><span> AnnotationConfigApplicationContext context <span style=color:#719e07>=</span> <span style=color:#719e07>new</span> AnnotationConfigApplicationContext(ConsumerConfiguration.class);
</span></span><span style=display:flex><span> context.start();
</span></span><span style=display:flex><span> GreetingServiceConsumer greetingServiceConsumer <span style=color:#719e07>=</span> context.getBean(GreetingServiceConsumer.class);
</span></span><span style=display:flex><span> String hello <span style=color:#719e07>=</span> greetingServiceConsumer.doSayHello(<span style=color:#2aa198>&#34;zookeeper&#34;</span>);
</span></span><span style=display:flex><span> System.out.println(<span style=color:#2aa198>&#34;result: &#34;</span> <span style=color:#719e07>+</span> hello);
</span></span><span style=display:flex><span> System.in.read();
</span></span><span style=display:flex><span> }
</span></span><span style=display:flex><span>}
</span></span></code></pre></div><p>The output are as follows:</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-shell data-lang=shell><span style=display:flex><span><span style=color:#719e07>[</span>03/08/18 01:42:31:031 CST<span style=color:#719e07>]</span> main INFO zookeeper.ZookeeperRegistry: <span style=color:#719e07>[</span>DUBBO<span style=color:#719e07>]</span> Register: consumer://192.168.99.1/com.alibaba.dubbo.samples.api.GreetingService?application<span style=color:#719e07>=</span>demo-consumer&amp;<span style=color:#268bd2>category</span><span style=color:#719e07>=</span>consumers&amp;<span style=color:#268bd2>check</span><span style=color:#719e07>=</span>false&amp;default.timeout<span style=color:#719e07>=</span>3000&amp;<span style=color:#268bd2>dubbo</span><span style=color:#719e07>=</span>2.6.2&amp;<span style=color:#268bd2>interface</span><span style=color:#719e07>=</span>com.alibaba.dubbo.samples.api.GreetingService&amp;<span style=color:#268bd2>methods</span><span style=color:#719e07>=</span>sayHello&amp;<span style=color:#268bd2>pid</span><span style=color:#719e07>=</span>82406&amp;<span style=color:#268bd2>side</span><span style=color:#719e07>=</span>consumer&amp;<span style=color:#268bd2>timestamp</span><span style=color:#719e07>=</span>1533274951195, dubbo version: 2.6.2, current host: 192.168.99.1 <span style=color:#586e75>#1</span>
</span></span><span style=display:flex><span><span style=color:#719e07>[</span>03/08/18 01:42:31:031 CST<span style=color:#719e07>]</span> main INFO zookeeper.ZookeeperRegistry: <span style=color:#719e07>[</span>DUBBO<span style=color:#719e07>]</span> Subscribe: consumer://192.168.99.1/com.alibaba.dubbo.samples.api.GreetingService?application<span style=color:#719e07>=</span>demo-consumer&amp;<span style=color:#268bd2>category</span><span style=color:#719e07>=</span>providers,configurators,routers&amp;default.timeout<span style=color:#719e07>=</span>3000&amp;<span style=color:#268bd2>dubbo</span><span style=color:#719e07>=</span>2.6.2&amp;<span style=color:#268bd2>interface</span><span style=color:#719e07>=</span>com.alibaba.dubbo.samples.api.GreetingService&amp;<span style=color:#268bd2>methods</span><span style=color:#719e07>=</span>sayHello&amp;<span style=color:#268bd2>pid</span><span style=color:#719e07>=</span>82406&amp;<span style=color:#268bd2>side</span><span style=color:#719e07>=</span>consumer&amp;<span style=color:#268bd2>timestamp</span><span style=color:#719e07>=</span>1533274951195, dubbo version: 2.6.2, current host: 192.168.99.1 <span style=color:#586e75>#2</span>
</span></span><span style=display:flex><span>...
</span></span><span style=display:flex><span>result: hello, zookeeper
</span></span></code></pre></div><p>Description:</p><ol><li><strong>Register</strong>: consumer://192.168.99.1/&mldr;&<strong>category=consumers</strong>&: In Zookeeper, consumers could register their information and store it at the <code>consumers</code> node</li><li><strong>Subscribe</strong>: consumer://192.168.99.1/&mldr;&<strong>category=providers,configurators,routers</strong>&:Consumers subscribe <code>providers</code>, <code>configurators</code>, <code>routers</code> from Zookeepers. The <code>configurations</code> is related to the Dubbo configuration, and <code>routers</code> is related to routing rules. The providers node subscription should be noted. When a new service provider to join, due to the relationship between the subscription, the new address list will be pushed to the subscriber. So service consumers also dynamically perceive changes in address lists.</li></ol><p>You could find the registration information of the service provider through the Zookeeper management terminal:</p><div class=highlight><pre tabindex=0 style=color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-sh data-lang=sh><span style=display:flex><span>$ docker <span style=color:#b58900>exec</span> -it zookeeper bash
</span></span><span style=display:flex><span>bash-4.4# bin/zkCli.sh -server localhost:218
</span></span><span style=display:flex><span>Connecting to localhost:2181
</span></span><span style=display:flex><span>...
</span></span><span style=display:flex><span>Welcome to ZooKeeper!
</span></span><span style=display:flex><span>JLine support is enabled
</span></span><span style=display:flex><span>...
</span></span><span style=display:flex><span><span style=color:#719e07>[</span>zk: localhost:2181<span style=color:#719e07>(</span>CONNECTED<span style=color:#719e07>)</span> 4<span style=color:#719e07>]</span> ls /dubbo/com.alibaba.dubbo.samples.api.GreetingService/consumers
</span></span><span style=display:flex><span><span style=color:#719e07>[</span>consumer%3A%2F%2F192.168.99.1%2Fcom.alibaba.dubbo.samples.api.GreetingService%3Fapplication%3Ddemo-consumer%26category%3Dconsumers%26check%3Dfalse%26default.timeout%3D3000%26dubbo%3D2.6.2%26interface%3Dcom.alibaba.dubbo.samples.api.GreetingService%26methods%3DsayHello%26pid%3D82406%26side%3Dconsumer%26timestamp%3D1533274951195<span style=color:#719e07>]</span>
</span></span></code></pre></div><p>You could see that consumers of Dubbo&rsquo;s servicehas registered its URL address at the <code>consumers</code> node:</p><p><em>consumer://192.168.99.1/com.alibaba.dubbo.samples.api.GreetingService?application=demo-consumer&amp;category=providers,configurators,routers&amp;default.timeout=3000&amp;dubbo=2.6.2&amp;interface=com.alibaba.dubbo.samples.api.GreetingService&amp;methods=sayHello&amp;pid=82406&amp;side=consumer&amp;timestamp=1533274951195</em></p><h2 id=summary>Summary</h2><p>This document focuses on how to use ZooKeeper as a registry in Dubbo. This document also mentioned that the Zookeeper could be a configuration center and a service management in Dubbo. Zookeeper is a single-node, standalone mode. However, developers always bulid a Zookeeper server cluster called * Zookeeper ensemble * in the real world.</p><p>Through this document, readers can learn:</p><ul><li>Basic concepts and applications of ZooKeeper</li><li>The function of Zookeeper in Dubbo application</li><li>Learn about Zookeeper&rsquo;s interaction through practical sample codes</li><li>The storage of service registration and consumption information of Dubbo with ZooKeeper</li></ul><div class=footnotes role=doc-endnotes><hr><ol><li id=fn:1><p><a href=https://www.apache.org/dyn/closer.cgi/zookeeper/>https://www.apache.org/dyn/closer.cgi/zookeeper/</a>&#160;<a href=#fnref:1 class=footnote-backref role=doc-backlink>&#8617;&#xfe0e;</a></p></li><li id=fn:2><p><a href=https://brew.sh>https://brew.sh</a>&#160;<a href=#fnref:2 class=footnote-backref role=doc-backlink>&#8617;&#xfe0e;</a></p></li><li id=fn:3><p><a href=https://www.docker.com/community-edition>https://www.docker.com/community-edition</a>&#160;<a href=#fnref:3 class=footnote-backref role=doc-backlink>&#8617;&#xfe0e;</a></p></li></ol></div><ul class="list-unstyled d-flex justify-content-between align-items-center mb-0 pt-5"><li><a href=/en/blog/2018/08/07/dubbo-101/ aria-label="Previous - Your First Dubbo Demo" class="btn btn-primary"><span class=mr-1></span>Previous</a></li><li><a href=/en/blog/2018/08/07/use-annotations-in-dubbo/ aria-label="Next - Use Annotations In Dubbo" class="btn btn-primary">Next<span class=ml-1></span></a></li></ul></div><div id=pre-footer><h2>Feedback</h2><p class=feedback--prompt>Was this page helpful?</p><button class="btn btn-primary mb-4 feedback--yes">Yes</button>
<button class="btn btn-primary mb-4 feedback--no">No</button></div><script>const yes=document.querySelector(".feedback--yes"),no=document.querySelector(".feedback--no");document.querySelectorAll(".feedback--link").forEach(e=>{e.href=e.href+window.location.pathname});const sendFeedback=e=>{gtag||console.log("!gtag"),gtag("event","click",{event_category:"Helpful",event_label:window.location.pathname,value:e})},disableButtons=()=>{yes.disabled=!0,yes.classList.add("feedback--button__disabled"),no.disabled=!0,no.classList.add("feedback--button__disabled")};yes.addEventListener("click",()=>{sendFeedback(1),disableButtons(),document.querySelector(".feedback--response").classList.remove("feedback--response__hidden")}),no.addEventListener("click",()=>{sendFeedback(0),disableButtons(),document.querySelector(".feedback--response").classList.remove("feedback--response__hidden")})</script></main><div class="d-none d-xl-block col-xl-2 td-toc d-print-none"><div class="td-page-meta ml-2 pb-1 pt-2 mb-0"><a href=https://github.com/apache/dubbo-website/edit/master/content/en/blog/news/dubbo-zk.md target=_blank><i class="fa fa-edit fa-fw"></i> Edit this page</a>
<a href="https://github.com/apache/dubbo-website/new/master/content/en/blog/news/dubbo-zk.md?filename=change-me.md&amp;value=---%0Atitle%3A+%22Long+Page+Title%22%0AlinkTitle%3A+%22Short+Nav+Title%22%0Aweight%3A+100%0Adescription%3A+%3E-%0A+++++Page+description+for+heading+and+indexes.%0A---%0A%0A%23%23+Heading%0A%0AEdit+this+template+to+create+your+new+page.%0A%0A%2A+Give+it+a+good+name%2C+ending+in+%60.md%60+-+e.g.+%60getting-started.md%60%0A%2A+Edit+the+%22front+matter%22+section+at+the+top+of+the+page+%28weight+controls+how+its+ordered+amongst+other+pages+in+the+same+directory%3B+lowest+number+first%29.%0A%2A+Add+a+good+commit+message+at+the+bottom+of+the+page+%28%3C80+characters%3B+use+the+extended+description+field+for+more+detail%29.%0A%2A+Create+a+new+branch+so+you+can+preview+your+new+file+and+request+a+review+via+Pull+Request.%0A" target=_blank><i class="fa fa-edit fa-fw"></i> Create child page</a>
<a href="https://github.com/apache/dubbo-website/issues/new?title=Using%20Zookeeper%20in%20Dubbo" target=_blank><i class="fab fa-github fa-fw"></i> Create an issue</a>
<a href=https://github.com/apache/dubbo/issues/new target=_blank><i class="fas fa-tasks fa-fw"></i> Create project issue</a></div><nav id=TableOfContents><ul><li><a href=#introduction-of-zookeeper>Introduction of Zookeeper</a><ul><li><a href=#the-basic-concept>The basic concept</a></li><li><a href=#basic-implementation>Basic Implementation</a></li></ul></li><li><a href=#using-zookeeper-in-dubbo>Using Zookeeper in Dubbo</a><ul><li><a href=#prepare-the-sample-code>Prepare the sample code</a></li></ul></li><li><a href=#summary>Summary</a></li></ul></nav><div class="taxonomy taxonomy-terms-cloud taxo-tags"><h5 class=taxonomy-title>Tags</h5><ul class=taxonomy-terms><li><a class=taxonomy-term href=https://cn.dubbo.apache.org/en/tags/ecosystem/ data-taxonomy-term=ecosystem><span class=taxonomy-label>ecosystem</span><span class=taxonomy-count>1</span></a></li><li><a class=taxonomy-term href=https://cn.dubbo.apache.org/en/tags/news/ data-taxonomy-term=news><span class=taxonomy-label>news</span><span class=taxonomy-count>1</span></a></li><li><a class=taxonomy-term href=https://cn.dubbo.apache.org/en/tags/opentelemetry/ data-taxonomy-term=opentelemetry><span class=taxonomy-label>OpenTelemetry</span><span class=taxonomy-count>1</span></a></li><li><a class=taxonomy-term href=https://cn.dubbo.apache.org/en/tags/tracing/ data-taxonomy-term=tracing><span class=taxonomy-label>tracing</span><span class=taxonomy-count>1</span></a></li></ul></div></div></div></div></div><footer class="bg-dark py-5 row d-print-none footer-margin-0"><div class="container-fluid mx-sm-5"><div class=row><div class="col-6 col-sm-4 text-xs-center order-sm-2"><ul class="list-inline mb-0"><li class="list-inline-item mx-2 h3" data-toggle=tooltip data-placement=top title="Dubbo mailing list archive" aria-label="Dubbo mailing list archive"><a class=text-white target=_blank rel="noopener noreferrer" href=https://lists.apache.org/list.html?dev@dubbo.apache.org><i class="fa fa-envelope"></i></a></li></ul></div><div class="col-6 col-sm-4 text-right text-xs-center order-sm-3"><ul class="list-inline mb-0"><li class="list-inline-item mx-2 h3" data-toggle=tooltip data-placement=top title=GitHub aria-label=GitHub><a class=text-white target=_blank rel="noopener noreferrer" href=https://github.com/apache/dubbo><i class="fab fa-github"></i></a></li><li class="list-inline-item mx-2 h3" data-toggle=tooltip data-placement=top title="Subscribe to mailing list" aria-label="Subscribe to mailing list"><a class=text-white target=_blank rel="noopener noreferrer" href=mailto:dev-subscribe@dubbo.apache.org><i class="fa fa-envelope"></i></a></li></ul></div><div class="col-12 col-sm-4 text-center py-2 order-sm-2"><small class=text-white>&copy; 2024 The Apache Software Foundation. Apache and the Apache feather logo are trademarks of The Apache Software Foundation. All Rights Reserved</small></div></div></div></footer><div class="row pt-2 pb-2 footer-margin-0"><div class="container-fluid mx-sm-5"><div class=text-center id=my-footer><img alt=apache_logo src=/imgs/apache_logo.png><ul><li><a href=https://www.apache.org>Foundation</a></li><li><a href=https://www.apache.org/licenses/>License</a></li><li><a href=https://dubbo.apache.org/en/overview/notices/>Security</a></li><li><a href=https://www.apache.org/events/current-event>Events</a></li><li><a href=https://www.apache.org/foundation/sponsorship.html>Sponsorship</a></li><li><a href=https://privacy.apache.org/policies/privacy-policy-public.html>Privacy</a></li><li><a href=https://www.apache.org/foundation/thanks.html>Thanks</a></li></ul></div></div></div><script src=/js/popper.min.js integrity=sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49 crossorigin=anonymous></script><script src=/js/bootstrap.min.js integrity=sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy crossorigin=anonymous></script><script src=/js/main.min.b075178d232d3b0039b3cb6af2fc2e9d90071820167a60f4eea3a79169975ee8.js integrity="sha256-sHUXjSMtOwA5s8tq8vwunZAHGCAWemD07qOnkWmXXug=" crossorigin=anonymous></script><script async src=https://widget.kapa.ai/kapa-widget.bundle.js data-website-id=d763c4f2-f871-400b-aeca-d986c4af73c2 data-project-name="Apache Dubbo" data-project-color=#E8442E data-button-text="Ask AI" data-search-mode-enabled=true data-modal-open-on-command-k=true data-modal-disclaimer="The AI supports multiple languages, but it may not be accessible in China due to recaptcha, a proxy is required." data-project-logo=https://pbs.twimg.com/profile_images/1011849068283191302/FJbH5vbF_400x400.jpg data-modal-example-questions="What is Apache Dubbo?,How to run Apache Dubbo?" data-button-position-top data-button-position-right=20px data-button-position-bottom=200px data-button-position-left></script><script>(function(e,t,n,s){e[s]=e[s]||[];var a=t.getElementsByTagName(n)[0],i=t.createElement(n);i.async=!0,i.id="beacon-aplus",i.setAttribute("exparams","userid=&aplus&sidx=aplusSidex&ckx=aplusCkx"),i.src="//g.alicdn.com/alilog/mlog/aplus_v2.js",i.crossorigin="anonymous",a.parentNode.insertBefore(i,a)})(window,document,"script","aplus_queue"),function(e){var t=e.createElement("script");t.type="text/javascript",t.async=!0,t.src="//g.alicdn.com/aes/??tracker/3.3.4/index.js,tracker-plugin-pv/3.0.5/index.js,tracker-plugin-event/3.0.0/index.js,tracker-plugin-autolog/3.0.3/index.js,tracker-plugin-survey/3.0.3/index.js,tracker-plugin-jserror/3.0.3/index.js,tracker-plugin-resourceError/3.0.3/index.js",t.onload=function(){window.AES_CONFIG=window.AES_CONFIG||{env:"prod"},window.aes=new AES({pid:"zN245h",user_type:6}),window.AESPluginAutologConfig={exposure:"auto"},window.AEMPluginInstances=[aes.use(AESPluginPV,window.AESPluginPVConfig||{enableHistory:!0}),aes.use(AESPluginEvent,window.AESPluginEventConfig||{}),aes.use(AESPluginSurvey,window.AESPluginEventConfig||{}),aes.use(AESPluginAutolog,window.AESPluginAutologConfig||{}),aes.use(AESPluginJSError,window.AESPluginJSError||{}),aes.use(AESPluginResourceError,window.AESPluginResourceError||{})]},setTimeout(function(){e.getElementsByTagName("body")[0].appendChild(t)},800)}(document)</script></body></html>