SpringBoot+Dubbo+Zookeeper ゝ一纸荒年。 2022-05-25 11:59 152阅读 0赞 **一、安装Zookeeper单机版(只用于demo,所以在Windows下安装)** * 官网下载[http://zookeeper.apache.org/][http_zookeeper.apache.org] **二、下载后解压,重命名,移至D:\\devsoft\\zookeeper** **三、在D:\\devsoft\\zookeeper 新建data及log目录** **四、到D:\\devsoft\\zookeeper\\conf 下复制 zoo\_sample.cfg 并粘贴到当前目录下,命名zoo.cfg** **五、编辑zoo.cfg.修改如下配置** **![20180416171433521][]** **六、cmd命令下进入D:\\devsoft\\zookeeper\\bin目录下运行 zkserver.cmd** **七、新建springboot-dubbo父工程,dubbo-provider、dubbo-consumer、dubbo-api子模块(dubbo-provider、dubbo-consumer依赖dubbo-api)** **八、dubbo-api 创建接口UserService** package com.zeke.dubboapi.service; public interface UserService { public String sayHello(); } **九、dubbo-provider创建接口实现UserServiceImpl** package com.zeke.dubboprovider.service.impl; import com.alibaba.dubbo.config.annotation.Service; import com.zeke.dubboapi.service.UserService; @Service public class UserServiceImpl implements UserService { @Override public String sayHello() { return "success"; } } * application.properties server.port=7001 #应用名称 spring.dubbo.application.name=dubbo-provider #注册中心地址 spring.dubbo.registry.address=zookeeper://10.0.0.36:2181 #暴露服务方式 spring.dubbo.protocol.name=dubbo #暴露服务端口 spring.dubbo.protocol.port=20880 #暴露服务包 spring.dubbo.scan=com.zeke.dubboprovider.service.impl **十、dubbo-consumer调用dubbo暴露的服务** package com.zeke.dubboconsumer.controller; import com.alibaba.dubbo.config.annotation.Reference; import com.zeke.dubboapi.service.UserService; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class UserController { @Reference UserService userService; @GetMapping("/sayHello") public String sayHello() { String result = userService.sayHello(); return result; } } * application.properties server.port=7002 #应用名称 spring.dubbo.application.name=dubbo-consumer #注册中心地址 spring.dubbo.registry.address=zookeeper://10.0.0.36:2181 #路径 spring.dubbo.scan=com.zeke.dubboconsumer.controller **十一、分别启动dubbo-consumer和dubbo-provider,访问localhost:7002/sayHello** [http_zookeeper.apache.org]: http://zookeeper.apache.org/ [20180416171433521]: /images/20220525/3a0da3d3d76844b781f9c688c8a8bfe0.png
还没有评论,来说两句吧...