dubbo uses zookeeper to connect

Build a zookeeper environment

1. Download the zookeeper.tar.gz compressed package (official website)
2. Use ftp to put the zookeeper.tar.gz compressed package into the virtual machine
3. Unzip tar -zxvf zookeeper.tar.gz -C /usr/local
4. Modify the configuration:
enter the decompressed folder, enter the conf directory, assign the zoo_sample.cfg file and rename it to zoo.cfg to
modify the zoo.cfg file: data_xxx configuration-"specify a folder (originally virtual)
5. In The fourth step is to execute the location of the folder to create a folder
6. Enter the bin directory and start zookeeper
./zkServer.sh start The
above steps will start zookeeper

Use zookeeper as middleware in the project

1. Import dependencies, you
need two
zookeeper
zkClients,
you can go directly to the Maven official website to find

2. Modify the applicationContext-service.xml file

<!--配置服务方名称(随便写,但是要保持唯一)-->
    <dubbo:application name="taotao-back-service"/>

 
    <!--使用zookeeper注册中心方式连接-->
    <dubbo:registry protocol="zookeeper" address="192.168.37.103:2181" />

     <!--注册服务
    interface:注册的接口,因为web层也引入了interface的依赖,这里直接声明,web就可以直接注入
    ref:引入你服务的类(service的实现类)-->
    <dubbo:service interface="com.ceh.back.service.TestService" ref="testServiceImpl"/>

The modification is completed can start the service layer, view the log if there is a heartbeat protocol (sent once every 10 seconds), that is successfully sent
3. Modify springmvc.xml

<!--配置dubbo-->
    <!--配置消费方名称(随便写,但唯一)-->
    <dubbo:application name="taotao-back-web"/>
   

    <!--使用zookeeper监控中心连接-->
    <dubbo:registry protocol="zookeeper" address="192.168.37.103:2181" />
    
    <!--消费
    id:对应web引入service服务的名称(autowired)
    interface:你在web层需要引入的接口
    这样dubbo就会把广播中对应的接口实现类给消费者-->
    <dubbo:reference  id="testService"  interface="com.ceh.back.service.TestService"/>

After the configuration is complete, zookeeper is used.

Guess you like

Origin blog.csdn.net/weixin_43431123/article/details/112134966