写在前面
这里记录下springboot-Dubbo的学习记录
准备找到官方提供的示例项目,clone到本地开发工具,项目地址
zookeeper 我这里用的 3.4.10 版本
还有zookeeper可视化工具 下载地址,
其实还有个 Dubbo-server-admin,也可以监控Dubbo服务,路由监控和发起RPC调用等.
一、启动 Zookeeper和可视化工具
windows窗口,双击zkServer.cmd或者命令行启动zk 可视化,解压后进入build目录执行命令java -jar zookeeper-dev-ZooInspector.jar
二、测试registry-samples --> zookeeper
先启动provider,再启动sumer
2.1 Provider配置、使用
application.properties
# Spring boot application
spring.application.name=dubbo-registry-zookeeper-provider-sampleLS
# Base packages to scan Dubbo Component: @.apache.dubbo.config.annotation.Service
dubbo.scan.base-packages=.apache.dubbo.spring.boot.sample.provider.service# Dubbo Application
## The default value of dubbo.application.name is ${spring.application.name}
## dubbo.application.name=${spring.application.name}# Dubbo Protocol
dubbo.protocol.name=dubbo
## Random port
dubbo.protocol.port=-1## Dubbo Registry
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.registry.file = ${user.home}/dubbo-cache/${spring.application.name}/dubbo.cache## DemoService version
demo.service.version=1.0.0
使用时用 DubboService,这里只是简单使用,还可以配置并发数,token等等
@DubboService(version = "${demo.service.version}")
public class DefaultDemoService implements DemoService {/*** The default value of ${dubbo.application.name} is ${spring.application.name}*/@Value("${dubbo.application.name}")private String serviceName;@Overridepublic String sayHello(String name) {return String.format("[%s] : Hello, %s", serviceName, name);}
}
2.2 Consumer
application.properties
spring:application:name: dubbo-registry-zookeeper-consumer-sampleLSdemo:service:version: 1.0.0embedded:zookeeper:port: 2181dubbo:registry:address: zookeeper://127.0.0.1:${embedded.zookeeper.port}file: ${user.home}/dubbo-cache/${spring.application.name}/dubbo.cache
使用,这种注入@DubboReference(version = “${demo.service.version}”),还可以配置 缓存,存根,负载均衡,参数等等
@DubboReference(version = "${demo.service.version}")private DemoService demoService;public ApplicationRunner runner() {return args -> logger.info(demoService.sayHello("mercyblitz"));}
2.3 ZK可视化,查看Dubbo服务节点元数据
三、测试 service-introspection-samples
这里涉及配置 dubbo.application.metadata-type=posite
参考ISSUE-Dubbo 2.7.8需要将本地和远程MetadataService组合为默认实现,本地MetadataService的优先级将高于远程的优先级。
更多推荐
Dubbo
发布评论