Dubbo详解+SpringBoot配置Dubbo

SpringBoot配置Dubbo

环境:spring-boot 2.0.1

org.springframework.boot
spring-boot-starter-parent
2.0.1.RELEASE


1 引入依赖
dubbo:

com.alibaba.spring.boot
dubbo-spring-boot-starter
2.0.0

zookeeper:

org.apache.zookeeper
zookeeper
3.4.6


org.slf4j
slf4j-log4j12


log4j
log4j

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:2181backup=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:2181backup=192.168.25.130:2181,192.168.25.131:2181

2 一样在Application上添加@EnableDubboConfiguration

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

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

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

你可能感兴趣的:(java,java,后端)