- 父工程:dubbo-parent
- 消费者:consumer
- 提供者:provider
- 通用模块:提供接口方法,消费者和提供者都需要引入。提供者需要实现该接口方法,消费者调用提供者暴露的实现方法时,需要提供一个和提供者一模一样接口(所以直接引用通用模块的接口)
- 父工程
4.0.0 org.example dubbo-parrentpom 1.0-SNAPSHOT consumer provider common 1.8 1.18.20 3.4.2 4.2.0 2.7.15 2.5.6 org.projectlombok lombok${lombok.version} org.springframework.boot spring-boot-starter-log4j2${springbootstartter.version} com.lmax disruptor${disruptor.version} org.apache.dubbo dubbo-spring-boot-starter${dubbo.version} org.apache.curator curator-framework${zookeeper.version} org.apache.curator curator-recipes${zookeeper.version} org.springframework.boot spring-boot-starter-web${springbootstartter.version} org.springframework.boot spring-boot-starter-loggingorg.apache.maven.plugins maven-surefire-plugin2.12.4 true org.springframework.boot spring-boot-maven-pluginorg.projectlombok lombokorg.springframework.boot spring-boot-maven-pluginrepackage org.apache.maven.plugins maven-surefire-plugintrue
- common
dubbo-parrent org.example 1.0-SNAPSHOT 4.0.0 common8 8 org.projectlombok lombokorg.apache.maven.plugins maven-surefire-plugin2.12.4 true org.springframework.boot spring-boot-maven-pluginorg.projectlombok lombokorg.springframework.boot spring-boot-maven-pluginrepackage org.apache.maven.plugins maven-surefire-plugintrue
- provider
dubbo-parrent org.example 1.0-SNAPSHOT 4.0.0 provider8 8 org.projectlombok lombokorg.springframework.boot spring-boot-starter-weborg.apache.dubbo dubbo-spring-boot-starterorg.springframework.boot spring-boot-starter-log4j2com.lmax disruptororg.apache.curator curator-frameworkorg.apache.curator curator-recipesorg.springframework.boot spring-boot-starter-test2.5.6 org.example common1.0-SNAPSHOT org.apache.maven.plugins maven-surefire-plugin2.12.4 true org.springframework.boot spring-boot-maven-pluginorg.projectlombok lombokorg.springframework.boot spring-boot-maven-pluginrepackage org.apache.maven.plugins maven-surefire-plugintrue
- consumer
三、配置文件dubbo-parrent org.example 1.0-SNAPSHOT 4.0.0 consumer8 8 org.projectlombok lombokorg.springframework.boot spring-boot-starter-weborg.apache.dubbo dubbo-spring-boot-starterorg.springframework.boot spring-boot-starter-log4j2com.lmax disruptororg.springframework.boot spring-boot-starter-test2.5.6 org.example common1.0-SNAPSHOT org.apache.curator curator-recipesorg.apache.maven.plugins maven-surefire-plugin2.12.4 true org.springframework.boot spring-boot-maven-pluginorg.projectlombok lombokorg.springframework.boot spring-boot-maven-pluginrepackage org.apache.maven.plugins maven-surefire-plugintrue
- provider
rocketmq:
name-server: 120.79.157.16:9876
producer:
group: dev-group
topic: dev
sync-tag: sync-tag
async-tag: async-tag
oneway-tag: oneway-tag
consumer:
topic: dev
group: dev-group
server:
port: 8082
zookeeper:
connect_string: 120.79.157.16
connection_timeout_ms: 15000
session_timeout_ms: 60000
spring:
application:
name: providerApp
dubbo:
scan:
base-packages: com.provider.service.impl
protocol:
name: dubbo
port: 9001
registry:
address: zookeeper://120.79.157.16:2181
application:
name: provider
- consumer
rocketmq:
name-server: 120.79.157.16:9876
producer:
group: dev-group
topic: dev
sync-tag: sync-tag
async-tag: async-tag
oneway-tag: oneway-tag
consumer:
topic: dev
group: dev-group
server:
port: 8081
spring:
application:
name: consumerApp
dubbo:
scan:
base-packages: com.consumer.service
protocol:
name: dubbo
port: 9002
registry:
address: zookeeper://120.79.157.16:2181
四、代码实现
代码结构不易展示,可以参考我的gitee链接,以下主要讲解一下实现过程
失效可以留下评论
- common提供接口方法和实体类,供provider和consumer使用。provider实现接口方法,需要使用@DubboService将接口暴露出来,供消费者调用。
- consumer使用@DubboReference引用provider暴露的接口。
- 先启动provider,再启用consumer



