在服务器端使用docker 下载Zookeeper镜像
docker pull ovfftd6p.mirror.aliyuncs.com/library/zookeeper
下载完成后启动Zookeeper
docker run -name zk01 --restart always -d -p 2181:2181 {IMAGE ID}
使用 docker ps 查看是否启动成功
官方文档:http://dubbo.apache.org/
github:
https://github.com/apache/dubbo
https://github.com/apache/dubbo-spring-boot-project
https://github.com/apache/dubbo-spring-boot-project/blob/0.2.x/README_CN.md
Dubbo是什么?
<dependency>
<groupId>com.alibaba.bootgroupId>
<artifactId>dubbo-spring-boot-starterartifactId>
<version>0.2.1.RELEASEversion>
dependency>
<dependency>
<groupId>com.alibabagroupId>
<artifactId>dubboartifactId>
<version>2.6.5version>
dependency>
<dependency>
<groupId>org.apache.curatorgroupId>
<artifactId>curator-recipesartifactId>
<version>2.12.0version>
dependency>
实体类
public class User implements Serializable {
private int id;
private String name;
private int age;
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
", age=" + age +
'}';
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
服务接口
public interface UserService {
public User getUserById(int id);
}
服务实现类
@Service
@com.alibaba.dubbo.config.annotation.Service
public class UserServiceImpl implements UserService {
@Override
public User getUserById(int id) {
User user = new User();
user.setId(id);
user.setAge(20);
user.setName("zzm");
return user;
}
}
application.properties
server.port=8081
spring.application.name=dubbo-provider-user
dubbo.application.name=dubbo-provider-user
dubbo.scan.base-packages=com.etc.service
dubbo.registry.address=zookeeper://192.168.88.128:2181
@SpringBootApplication
@EnableDubbo
public class DemoproviderApplication {
public static void main(String[] args) {
SpringApplication.run(DemoproviderApplication.class, args);
}
}
执行springboot启动类
<dependency>
<groupId>com.alibaba.bootgroupId>
<artifactId>dubbo-spring-boot-starterartifactId>
<version>0.2.1.RELEASEversion>
dependency>
<dependency>
<groupId>com.alibabagroupId>
<artifactId>dubboartifactId>
<version>2.6.5version>
dependency>
<dependency>
<groupId>org.apache.curatorgroupId>
<artifactId>curator-recipesartifactId>
<version>2.12.0version>
dependency>
实体类和服务接口 与provider一致
ConUserService
public interface ConUserService {
public User getUserById(int id);
}
ConUserServiceImpl
@Service
public class ConUserServiceImpl implements ConUserService {
@Reference
private UserService userService;
@Override
public User getUserById(int id) {
return userService.getUserById(1);
}
}
UserController
@RestController
public class UserController {
@Autowired
private ConUserService service;
@GetMapping("user/{id}")
public User getById(@PathVariable("id") int id){
User userById = service.getUserById(id);
return userById;
}
}
application.properties
server.port=8082
spring.application.name=dubbo-consumer-user
dubbo.application.name=dubbo-consumer-user
dubbo.registry.address=zookeeper://192.168.88.128:2181
执行springboot启动类
自己封装了一个jar 可以直接使用
需要修改的地方
修改完后打开cmd 使用java -jar jar包