发表于: 2020-09-23 20:08:26
1 1425
今天完成的事:
dubbo+springboot demo
首先要下载zookeepr注册中心
去github下载dubbo-admin-server
进入目录用maven打包,然后执行jar包
输入默认密码进入到如下界面
新建一个空项目,然后建立两个独立的moudle,分别是生产者和消费者
生产者provider和消费引入的依赖:
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.7.8</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>2.7.8</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>2.8.0</version>
</dependency>
生产者的application.properties配置
server.port=8002
dubbo.application.name=provider-server
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.scan.base-packages=com.jnshu.service
dubbo.protocol.name=dubbo
dubbo.protocol.port=20880
接口实现类加上@DubboServer注解
@DubboService
public class TestServiceImpl implements TestService{
@Override
public String sayHi() {
return "Hi,dubbo";
}
}
消费者的application.properties
server.port=8001
dubbo.application.name=consumer-server
dubbo.registry.address=zookeeper://127.0.0.1:2181
在消费者中创建一个跟生产者同样的接口。
public interface TestService {
public String sayHi();
}
引用生产者提供的服务
@Service
public class UserService {
@DubboReference
TestService testService;
public String sayHi(){
return testService.sayHi();
}
}
创建一个controller测试
@RestController
public class TestController {
@Autowired
UserService userService;
@RequestMapping("/hi")
public String sayHi(){
return userService.sayHi();
}
}
启动zookeeper注册中心:
测试结果
查看dubbo管理控制台:
明天的计划:学习shiro和spring Security
遇到的问题:
收获:
Dubbo的配置。
评论