(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. SpringCloud与微服务Ⅸ --- Zuul路由网关

    一.Zool是什么 Zuul包含了对请求路由和过滤两个最主要的功能: 其中路由功能负责将外部请求转发到具体的微服务实例上,是实现外部访问统一入口的基础而过滤器功能则负责对请求的处理过程进行干预,是实现 ...

  2. 单点登陆(SSO)

    一.背景 在企业发展初期,企业使用的系统很少,通常一个或者两个,每个系统都有自己的登录模块,运营人员每天用自己的账号登录,很方便.但随着企业的发展,用到的系统随之增多,运营人员在操作不同的系统时,需要 ...

  3. Docker深入浅出系列 | Image实战演练

    目录 课程目标 Container与Image核心知识回顾 制作Docker Image的两种方式 Dockerfile常用指令 Image实战篇 通过Dockerfile制作Image 通过Dock ...

  4. 1、通过CP数据文件的方式恢复MySQL 从库 启动后报错:Last_IO_Errno: 1236:A slave with the same server_uuid/server_id as this slave has connected to the master;

    1.问题: MySQL从库中查看主从状态: show slave status\G,发现出现IO的报错: Last_IO_Errno: Last_IO_Error: Got fatal error f ...

  5. C语言系列之自增自减运算符的用法(二)

    运算符中最难理解的有自增自减运算符的使用方法,下面我将简单总结一下他们的使用方法 我们知道,C语言运行是由右向左运行的 下面我们来看一个例子 当i等于3的时候 j=++i; 由上面可知,C语言是由右向 ...

  6. 《快乐编程大本营》java语言训练班 2课:java的变量

    <快乐编程大本营>java语言训练班 2课:java的变量 1变量介绍 2变量分类,数值变量 3变量分类-字符串变量 4变量分类-布尔变量 5变量分类-对象 http://code6g.c ...

  7. LUA学习笔记(第1-4章)

    需要一种简单的脚本语言来代替批处理,它需要足够小巧,同时功能上也应该足够强劲,自然选择了LUA语言. 第一章 Hello World print('Hello World') print(" ...

  8. GetModuleFileNameEx遍历获取64bit程序路径失败的一种解决方法(Win7-64-bit)

    问题: 32位程序在64位系统上调用GetModuleFileNameEx()遍历获取64位进程的全路径失败,得到的路径都为空. 根据官方的说法: For the best results use t ...

  9. Guava入门使用教程

    Guava入门使用教程 Guava Maven dependency In our examples, we use the following Maven dependency. <depen ...

  10. Linux系统基础认知

    什么是操作系统? 操作系统作为接口的示意图: 没有安装操作系统的计算机,通常被称为裸机 如果想在 裸机 上运行自己所编写的程序,就必须用机器语言书写程序 如果计算机上安装了操作系统,就可以在操作系统上 ...