(PS. 随缘看心情写,坚持不了几天。文章还是写的超级的烂,排版也奇差无比~~~~ 脑壳疼~~~)

1. 相关知识

  1. netty

  2. netty多线程模型:Reactor模型

  3. protobuf(Google Protocol Buffers)

    “在以不同语言编写并在不同平台上运行的应用程序之间交换数据时,Protobuf 编码可提高效率。”

    个人也没有去大致了解过,只是因为启动seata-server时报错才看到的。

    参考:

    github, protobuf

    深入 ProtoBuf - 简介

  4. "com.typesafe.config"

    "configuration library for JVM languages using HOCON files"

    例如seata中主要的2个配置文件register.conffile.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 本地安装

下载地址:github, protobuf-release

特别:通过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

  1. idea安装插件Protobuf Support(proto语法高亮,mvn编译命令)
  1. 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>
  1. 手动编译,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 备注

  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;
}
}
  1. 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. ...
  1. 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. 总结

  1. seata配置的加载

    seata配置加载类(factory模式):io.seata.config.ConfigurationFactory

    不同config.type对应的加载扩展:io.seata.config.ConfigurationProvide

  2. register.conf

    其中只有2个配置:

    a)register.type,将seata-server注册到什么地方。

    b)confi.type,seata-server的一些核心配置。例如"store.mode",seata-server如何记录transaction log。

  3. seata-server注册到什么地方

    io.seata.discovery.registry.RegistryFactory 注册类(factory模式)

    根据从register.conf中配置的不同register.type,调用相应io.seata.discovery.registry.RegistryProvider的实现类。

【seata源码学习】001 - seata-server的配置读取和服务注册的更多相关文章

  1. 源码学习系列之SpringBoot自动配置(篇二)

    源码学习系列之SpringBoot自动配置(篇二)之HttpEncodingAutoConfiguration 源码分析 继上一篇博客源码学习系列之SpringBoot自动配置(篇一)之后,本博客继续 ...

  2. SpringBoot源码学习系列之异常处理自动配置

    SpringBoot源码学习系列之异常处理自动配置 1.源码学习 先给个SpringBoot中的异常例子,假如访问一个错误链接,让其返回404页面 在浏览器访问: 而在其它的客户端软件,比如postm ...

  3. 源码学习系列之SpringBoot自动配置(篇一)

    源码学习系列之SpringBoot自动配置源码学习(篇一) ok,本博客尝试跟一下Springboot的自动配置源码,做一下笔记记录,自动配置是Springboot的一个很关键的特性,也容易被忽略的属 ...

  4. SpringBoot源码学习系列之SpringMVC自动配置

    目录 1.ContentNegotiatingViewResolver 2.静态资源 3.自动注册 Converter, GenericConverter, and Formatter beans. ...

  5. 『TensorFlow』SSD源码学习_其五:TFR数据读取&数据预处理

    Fork版本项目地址:SSD 一.TFR数据读取 创建slim.dataset.Dataset对象 在train_ssd_network.py获取数据操作如下,首先需要slim.dataset.Dat ...

  6. SpringBoot源码学习系列之Locale自动配置

    目录 1.spring.messages.cache-duration 2.LocaleResolver 的方法名必须为localeResolver 3.默认LocaleResolver 4.指定默认 ...

  7. Spring源码阅读笔记03:xml配置读取

    前面的文章介绍了IOC的概念,Spring提供的bean容器即是对这一思想的具体实现,在接下来的几篇文章会侧重于探究这一bean容器是如何实现的.在此之前,先用一段话概括一下bean容器的基本工作原理 ...

  8. 【spring源码学习】spring的task配置

    =================spring线程池的配置策略含义========================== id:当配置多个executor时,被@Async("id" ...

  9. 03.ElementUI源码学习:代码风格检查和格式化配置(ESlint & Prettier)

    书接上文.在团队协作中,为避免低级Bug.以及团队协作时不同代码风格对彼此造成的困扰与影响,会预先制定编码规范.使用 Lint工具和代码风格检测工具,则可以辅助编码规范执行,格式化代码,使样式与规则保 ...

随机推荐

  1. 【阿K学Python系列】一Python基础语法(二)

    前言 通过上一章的学习[阿k学Python]一Python入门(一),我们已经初步了解到Python是一种解释型.面向对象.动态数据类型的高级程序设计语言,当然也是一门脚本语言,像前端需要学习的Jav ...

  2. 用WORD批量制作工作证件

    用WORD批量制作工作证件 一.采集电子照片 电子照片的采集要求以的名字作为照片的文件名,保存为“.jpg”格式,尺寸和大小需保持一致. 二.制作信息表 制作Exice数据信息表,包含姓名.年龄.部门 ...

  3. Linux下安装nvidia显卡驱动

    部署环境 操作系统:Centos 7.4 在线源:Centos 7.4镜像源 安装操作 1.安装系统插件 [root@localhost ~]# yum -y install gcc kernel-d ...

  4. centos7下oracle11g详细的安装与建表操作

    一.oracle的安装,在官网下载oracle11g R2 1.在桌面单击右键,选择“在终端中打开”,进入终端 输入命令:su 输入ROOT密码: 创建用户组oinstall:groupadd oin ...

  5. git看这一篇就够用了

    前言 本文是参考廖雪峰老师的Git资料再加上我自己对Git的理解,记录我的Git学习历程. Git是什么 官方话:Git是一个免费的开源分布式版本控制系统,旨在快速高效地处理从小型到大型项目的所有事务 ...

  6. 《快乐编程大本营》java语言训练班 1课:第一个java程序:你好,范冰冰;

    1Java介绍 2安装java环境JDK 3安装web环境tomcat 4安装开发工具Idea2017 5编写第一个程序 ‘你好,范冰冰!’ 地址: http://code6g.com 1.Java介 ...

  7. FMPEG结构体分析:AVStream

    注:写了一系列的结构体的分析的文章,在这里列一个列表: FFMPEG结构体分析:AVFrame FFMPEG结构体分析:AVFormatContext FFMPEG结构体分析:AVCodecConte ...

  8. top100tools

    Top 100 Tools for Learning 2013 2142 EmailShare Here are the Top 100 Tools for Learning 2013 –  the ...

  9. CSS的常用单位介绍

    ①px: 像素单位:它是英文单词pixel的缩写,意思为像素,即构成图片的每一个点,为图片显示的最小单位.它是一个绝 对尺寸单位,是固定的. ②em: 相对长度单位:它是英文单词emphasize的缩 ...

  10. OpenCV3入门(六)图像滤波

    1.图像滤波理论 1.1图像滤波理论 图像滤波即在尽量保留图像细节特征的条件下对目标图像的噪声进行抑制,是图像预处理中不可缺少的操作.消除图像中的噪声又叫做图像滤波或平滑,滤波的目的有两个,一是突出特 ...