青青草原羊村中,对于几只调皮的小羊,特别是懒羊羊,慢羊羊村长可是费了不少心思呢。几只小羊尚且如此,那么对于服务的治理,我们该怎么办呢。
为了解决服务治理,阿里专门开发了服务治理的RPC框架- Dubbo
,对于这个,你岂能不了解呢~~
该教程,用于了解Dubbo + zookeeper的使用,之后会有其原理介绍与代码分析。
tickTime=2000 dataDir= ../data (填写自己的data目录) dataLogDir=../logs clientPort=2181 复制代码
./bin/zkServer.sh start
,成功如下: ZooKeeper JMX enabled by default Using config: /Users/zyq/develomentEnvir/zookeeper-3.4.12/bin/../conf/zoo.cfg Starting zookeeper ... STARTED 复制代码
package com.chezhe; public interface CheZheService { String hello(); } 复制代码
package com.chezhe; public interface CheZheService2 { String hello(); } 复制代码
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>io.dubbo.springboot</groupId> <artifactId>spring-boot-starter-dubbo</artifactId> </dependency> <dependency> <groupId>com.chezhe</groupId> <artifactId>core</artifactId> <version>1.1-SNAPSHOT</version> </dependency> 复制代码
# 端口号配置 server.port=8081 #dubbo配置 spring.dubbo.application.name=provider //随便填 spring.dubbo.registry.address=zookeeper://127.0.0.1:2181 //zk地址 spring.dubbo.protocol.name=dubbo //设置RPC协议为dubbo协议 spring.dubbo.protocol.port=25040 //生产者暴露的服务端口 spring.dubbo.scan=com.chezhe //需要扫描的包(带有service注解的类) spring.dubbo.consumer.check=false spring.dubbo.timeout=10000 //调用dubbo超时时间 复制代码
package com.chezhe.service.impl; @Service public class CheZheServiceImpl implements CheZheService { @Override public String hello() { return "你好,车辙"; } } 复制代码
package com.chezhe.service.impl; @Service public class CheZheServiceImpl2 implements CheZheService2 { @Override public String hello() { return "你好,车辙"; } } 复制代码
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>io.dubbo.springboot</groupId> <artifactId>spring-boot-starter-dubbo</artifactId> </dependency> <dependency> <groupId>com.chezhe</groupId> <artifactId>core</artifactId> <version>1.1-SNAPSHOT</version> </dependency> 复制代码
# 端口号配置 server.port=8082 #dubbo配置 spring.dubbo.application.name=consumer //随便填 spring.dubbo.registry.address=zookeeper://127.0.0.1:2181 //zk地址 spring.dubbo.scan=com.chezhe //需要扫描的包(带有service注解的类) spring.dubbo.consumer.check=false spring.dubbo.timeout=10000 //调用dubbo超时时间 复制代码
@RestController public class CheZheController { @Reference private CheZheService cheZheService; @RequestMapping(value = "/cheZheTest",method = RequestMethod.GET) public String cheZheTest(){ return cheZheService.hello(); } } 复制代码