Dubbo详解+SpringBoot配置Dubbo

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/LIAN_XL/article/details/79999205

SpringBoot配置Dubbo

环境:spring-boot 2.0.1
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
1 引入依赖
dubbo:
<dependency>
<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
zookeeper:
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>

</dependency>

provider配置:

1  application.properties配置:
spring.dubbo.application.id=live-dubbo-provider  
spring.dubbo.application.name=live-dubbo-provider  
spring.dubbo.registry.address=zookeeper://192.168.25.129:2181?backup=192.168.25.130:2181,192.168.25.131:2181
spring.dubbo.server=true
spring.dubbo.protocol.name=dubbo
spring.dubbo.protocol.port=20880

2  Application上添加注解:@EnableDubboConfiguration

3  service实现类上添加dubbo的@Service和spring的@Component

启动provider服务即可注册成功,打开dubbo-admin监控中心可以看到已经注册

consumer配置:
1  application.properties配置:
server.port=8081  
  
spring.dubbo.application.name=live-dubbo-consumer  
spring.dubbo.application.id=live-dubbo-consumer  
spring.dubbo.protocol.port=20800  
spring.dubbo.protocol.name=dubbo  

spring.dubbo.registry.address=zookeeper://192.168.25.129:2181?backup=192.168.25.130:2181,192.168.25.131:2181

 

2  一样在Application上添加@EnableDubboConfiguration

3  controller引入service,serviec接口上添加dubbo的@Reference注解

启动服务即可,浏览器也可以获取数据


dubbo有很多中容错策略,最常用的就是快速失败策略(出错后不重复提交,直接抛出异常)或者按上述说的把retries重试次数设置为0,也就是不做重复尝试。

展开阅读全文

没有更多推荐了,返回首页