Dubbo学习记录1

编程入门 行业动态 更新时间:2024-10-27 22:21:13

写在前面

这里记录下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

本文发布于:2023-05-20 18:53:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/154776.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Dubbo

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!