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;