SpringBoot+zk+dubbo个人分析

1.先下载zookeeper压缩包,解压后在conf文件中新增zoo.cfg

  单机模式:

# The number of milliseconds of each tick  心跳间隔 毫秒每次
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting anacknowledgement
syncLimit=5
# the directory where the snapshot isstored.  //镜像数据位置
dataDir=F:\wds\zookeeper-3.4.8\\data\\zookeeper
#日志位置
dataLogDir=F:\wds\zookeeper-3.4.8\\logs\\zookeeper
# the port at which the clients willconnect  客户端连接的端口
clientPort=2181
server.1=127.0.0.1:2888:3888.

2.新建2个工程,SpringProvider(生产提供者)、SpringConsumer(消费者)

SpringProvider(生产提供者)中暴露服务接口,例如:

## Dubbo 服务提供者配置
spring.dubbo.application.name=provider
spring.dubbo.registry.address=zookeeper://127.0.0.1:2181
spring.dubbo.protocol.name=dubbo
spring.dubbo.protocol.port=20880
spring.dubbo.scan=com.springboot.demoDu.service

但是如果是用Spring的话,则在xml文件中加

<!-- 声明需要暴露的服务接口 -->
 

<dubbo:service interface="egg.operate.service.api.platformData.IBrandService" ref="brandService"></dubbo:service>

在消费者中则写

<dubbo:reference interface="egg.operate.service.api.platformData.IBrandService" id="brandService"></dubbo:reference>

在SpringConsumer(消费者)中用注解的形式调用服务接口

@Reference
    UserService userService;

猜你喜欢

转载自blog.csdn.net/wudiansheng/article/details/83303839