1、在pom中引入dubbo的依赖
<dependency>
<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
2、在配置文件中配置dubbo的注册中心
(1)简单配置
spring.dubbo.application.id=order
spring.dubbo.application.name= order
spring.dubbo.registry.address= zookeeper://192.168.1.1:2181?backup= 192.168.1.2 :2181, 192.168.1.3 :2181
(2)消费者和提供者group、注册中心不同的配置
spring.dubbo.application.id=order
spring.dubbo.application.name= order
spring.dubbo.registries.orderCenter.group=order
spring.dubbo.registries.orderCenter.address= zookeeper://192.168.1.1:2181?backup= 192.168.1.2 :2181, 192.168.1.3 :2181
spring.dubbo.registries.userCenter.group=user
spring.dubbo.registries.busTicket.address=zookeeper://192.168.1.1:2181?backup= 192.168.1.2 :2181, 192.168.1.3 :2181
spring.dubbo.provider.filter=dubboServiceFilter
spring.dubbo.consumer.filter=dubboServiceFilter
dubbo的过滤器配置最后面会讲dubboServiceFilter
3、发布dubbo接口( registry 指定的是上面不同group的方式 )
@Service(registry = "orderCenter")
@Component
public class OrderService{
.....
}
service 注解用的是com.alibaba.dubbo.config.annotation.Service
4、引用dubbo方式
@Reference(registry = "userCenter", interfaceClass = IUserService.class, timeout = 15000, retries = 0, check = false)
UserService userService;
reference注解用的是com.alibaba.dubbo.config.annotation.Reference
网友评论