【seata源码学习】001 - seata-server的配置读取和服务注册
(PS. 随缘看心情写,坚持不了几天。文章还是写的超级的烂,排版也奇差无比~~~~ 脑壳疼~~~)
1. 相关知识
netty
netty多线程模型:Reactor模型
protobuf(Google Protocol Buffers)
“在以不同语言编写并在不同平台上运行的应用程序之间交换数据时,Protobuf 编码可提高效率。”
个人也没有去大致了解过,只是因为启动seata-server时报错才看到的。
参考:
github, protobuf
深入 ProtoBuf - 简介"com.typesafe.config"
"configuration library for JVM languages using HOCON files"
例如seata中主要的2个配置文件register.conf和file.conf,底层都是依赖"com.typesafe.config"读取并解析其配置。
参考:
github, com.typesafe.config
2. protobuf(Google Protocol Buffers)
启动seata-server时遇到的问题:
E:\Workspace Git\seata-fork\codec\seata-codec-protobuf\src\main\java\io\seata\codec\protobuf\convertor\BranchCommitRequestConvertor.java
Error:(19, 41) java: 程序包io.seata.codec.protobuf.generated不存在
通过查找protobuf的资料...BALABALABALA...
2.1 protobuf 本地安装
特别:通过maven-plugin来编译proto文件,可能不需要这么安装protobuf。(ps. 搞懵逼了,i'm five~~)
注意windows下载的是protoc-3.11.3-win64.zip,而不是protobuf-java-3.11.3.zip(这个需要自己编译)。
下载并解压后,将bin目录添加到环境变量 - 系统变量 - path。通过cmd验证是否安装成功:
PS C:\Users\Administrator> protoc --version
libprotoc 3.11.3
2.2 protobuf-maven-plugin
- idea安装插件
Protobuf Support(proto语法高亮,mvn编译命令)
- maven-plugin 配置,例如seata源码中的相应 pom.xml
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>${protobuf-maven-plugin.version}</version>
<configuration>
<protoSourceRoot>${project.basedir}/src/main/resources/protobuf/io/seata/protocol/transcation/</protoSourceRoot>
<protocArtifact>
com.google.protobuf:protoc:3.3.0:exe:${os.detected.classifier}
</protocArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
- 手动编译,idea中
Maven - {seata-codec-protobuf 1.0.0} - plugins - protobuf - [protobuf:compile | protobuf:compile-javanano]。
关于protobuf:compile或者protobuf:compile-javanano并不清楚其具体的含义。
大致的表面现象是,最终生成的代码在target/generated-sources下目录不一样。
到此,IDEA中查看例如"io.seata.codec.protobuf.convertor.BranchCommitRequestConvertor"不在报错。
2.3 扩展,protobuf生成代码缺少"com.google.protobuf.nano.*"
为了解决这个问题,我在codec/seata-codec-protobuf/pom.xml中增加了其MAVEN依赖:
<!-- vergilyn-comment, 2020-02-13 >>>> 添加 -->
<dependency>
<groupId>com.google.protobuf.nano</groupId>
<artifactId>protobuf-javanano</artifactId>
<version>3.1.0</version>
</dependency>
3. 配置文件的读取(register.conf、file.conf)

4. 将seata-server注册到服务注册中心(例如eureka、nacos)

4.1 备注
- seata v1.0.0中,通过nacos获取conf并不支持指定GROUP,默认从
SEATA_GROUP获取(在下一个版本开始支持配置GROUP)。
package io.seata.config.nacos;
public class NacosConfiguration extends AbstractConfiguration {
private static final String SEATA_GROUP = "SEATA_GROUP";
@Override
public String getConfig(String dataId, String defaultValue, long timeoutMills) {
String value;
if ((value = getConfigFromSysPro(dataId)) != null) {
return value;
}
try {
value = configService.getConfig(dataId, SEATA_GROUP, timeoutMills);
} catch (NacosException exx) {
LOGGER.error(exx.getErrMsg());
}
return value == null ? defaultValue : value;
}
}
- question: 现在seata支持的nacos的配置是一项一项的(nacos的dataId过多)
store {
## store mode: file、db
mode = "db"
## database store property
db {
datasource = "druid"
db-type = "mysql"
driver-class-name = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://127.0.0.1:3306/test_microservice"
user = "root"
password = "123456"
}
}
对应的是7个data-id,而不是一个data-id中的key-value:
1. store.mode
2. store.db.datasource
3. store.db.db-type
4. ...
- seata注册到nacos的服务名默认叫“serverAddr”
相关代码参考:io.seata.discovery.registry.nacos.NacosRegistryServiceImpl#register(...)
package io.seata.discovery.registry.nacos;
public class NacosRegistryServiceImpl implements RegistryService<EventListener> {
private static final String PRO_SERVER_ADDR_KEY = "serverAddr";
@Override
public void register(InetSocketAddress address) throws Exception {
validAddress(address);
// vergilyn-question, 2020-02-13 >>>> FIXME,注册到nacos的serviceName始终是“serverAddr”
getNamingInstance().registerInstance(PRO_SERVER_ADDR_KEY, address.getAddress().getHostAddress(), address.getPort(), getClusterName());
}
}
5. 总结
seata配置的加载
seata配置加载类(factory模式):io.seata.config.ConfigurationFactory
不同config.type对应的加载扩展:io.seata.config.ConfigurationProvideregister.conf
其中只有2个配置:
a)register.type,将seata-server注册到什么地方。
b)confi.type,seata-server的一些核心配置。例如"store.mode",seata-server如何记录transaction log。seata-server注册到什么地方
io.seata.discovery.registry.RegistryFactory注册类(factory模式)
根据从register.conf中配置的不同register.type,调用相应io.seata.discovery.registry.RegistryProvider的实现类。
【seata源码学习】001 - seata-server的配置读取和服务注册的更多相关文章
- 源码学习系列之SpringBoot自动配置(篇二)
源码学习系列之SpringBoot自动配置(篇二)之HttpEncodingAutoConfiguration 源码分析 继上一篇博客源码学习系列之SpringBoot自动配置(篇一)之后,本博客继续 ...
- SpringBoot源码学习系列之异常处理自动配置
SpringBoot源码学习系列之异常处理自动配置 1.源码学习 先给个SpringBoot中的异常例子,假如访问一个错误链接,让其返回404页面 在浏览器访问: 而在其它的客户端软件,比如postm ...
- 源码学习系列之SpringBoot自动配置(篇一)
源码学习系列之SpringBoot自动配置源码学习(篇一) ok,本博客尝试跟一下Springboot的自动配置源码,做一下笔记记录,自动配置是Springboot的一个很关键的特性,也容易被忽略的属 ...
- SpringBoot源码学习系列之SpringMVC自动配置
目录 1.ContentNegotiatingViewResolver 2.静态资源 3.自动注册 Converter, GenericConverter, and Formatter beans. ...
- 『TensorFlow』SSD源码学习_其五:TFR数据读取&数据预处理
Fork版本项目地址:SSD 一.TFR数据读取 创建slim.dataset.Dataset对象 在train_ssd_network.py获取数据操作如下,首先需要slim.dataset.Dat ...
- SpringBoot源码学习系列之Locale自动配置
目录 1.spring.messages.cache-duration 2.LocaleResolver 的方法名必须为localeResolver 3.默认LocaleResolver 4.指定默认 ...
- Spring源码阅读笔记03:xml配置读取
前面的文章介绍了IOC的概念,Spring提供的bean容器即是对这一思想的具体实现,在接下来的几篇文章会侧重于探究这一bean容器是如何实现的.在此之前,先用一段话概括一下bean容器的基本工作原理 ...
- 【spring源码学习】spring的task配置
=================spring线程池的配置策略含义========================== id:当配置多个executor时,被@Async("id" ...
- 03.ElementUI源码学习:代码风格检查和格式化配置(ESlint & Prettier)
书接上文.在团队协作中,为避免低级Bug.以及团队协作时不同代码风格对彼此造成的困扰与影响,会预先制定编码规范.使用 Lint工具和代码风格检测工具,则可以辅助编码规范执行,格式化代码,使样式与规则保 ...
随机推荐
- Web自动化测试项目搭建目录
Web自动化测试项目搭建(一) 需求与设计 Web自动化测试项目(二)BasePage实现 Web自动化测试项目(三)用例的组织与运行 Web自动化测试项目(四)测试报告 Web自动化测试项目(五)测 ...
- 一个基于RabbitMQ的可复用的事务消息方案
前提 分布式事务是微服务实践中一个比较棘手的问题,在笔者所实施的微服务实践方案中,都采用了折中或者规避强一致性的方案.参考Ebay多年前提出的本地消息表方案,基于RabbitMQ和MySQL(JDBC ...
- GO异常 | runnerw.exe: CreateProcess failed with error 21
背景 今天创建了一个GO项目,写了几行代码 package chapter1 import "fmt" func main() { fmt.Println("hello ...
- 技术部突然宣布:JAVA开发人员全部要会接口自动化测试框架
整理了一些Java方面的架构.面试资料(微服务.集群.分布式.中间件等),有需要的小伙伴可以关注公众号[程序员内点事],无套路自行领取 写在前边 用单元测试Junit完全可以满足日常开发自测,为什么还 ...
- codeforces 1020 C Elections(枚举+贪心)
题意: 有 n个人,m个党派,第i个人开始想把票投给党派pi,而如果想让他改变他的想法需要花费ci元.你现在是党派1,问你最少花多少钱使得你的党派得票数大于其它任意党派. n,m<3000 思路 ...
- meta 的作用 搜集
Meta标签中的format-detection属性及含义 format-detection翻译成中文的意思是“格式检测”,顾名思义,它是用来检测html里的一些格式的,那关于meta的forma ...
- Apache Tomcat Ajp-CVE-2020-1938漏洞复现
环境搭建: sudo docker pull duonghuuphuc/tomcat-8.5.32 sudo docker run -d -it -p 8080:8080 -p 8009:8009 ...
- Params:params 关键字可以指定在参数数目可变处采用参数的方法参数。
Params:params 关键字可以指定在参数数目可变处采用参数的方法参数. 注意点: 1.一个方法中只能使用一个params来声明不定长参数数组: 2.params参数数组只能放在已定义参数后面 ...
- 踩坑ThinkPHP5之模型对象返回的数据集如何转为数组
各位小伙伴们大家好,冷月今天在做项目的过程中呢,遇到了一个坑就是用tp5的模型操作数据库时,返回的是数据集而不是直接的数组.于是冷月就想办法如何将数据集转为数组.写下这篇博文,防止大家遇到这个坑时可以 ...
- IP multicast IP多播
https://networklessons.com/multicast/multicast-routing/ IP多播有两种模式,密集模式和稀疏模式: Dense Mode Sparse Mode ...