配置中心配置文件
配置中心读取配置的流程
- 选择配置文件, 例如registry.conf
- 根据配置文件的文件类型选择基础配置
- 通过基础配置进行驱动, 加载核心配置
seata 在加载核心配置的时候, 会放到本地的 ConcurrentHashMap 缓存。 取值时可以分为三个级别:
- 优先从缓存中获取
- 从 System.getProperty 获取
- 从配置中心获取
如果取到值会存放到缓存中
选择配置文件
配置中心配置文件默认是: registry.conf , 可以通过系统属性(System.getProperty),环境变量(System.getenv)指定配置中心配置文件
配置的属性优先获取系统属性值,如果不存在在获取环境变量的配置,如果还没有就获取默认值
系统属性方式 | 环境变量方式 | 默认值 |
---|---|---|
seata.config.name | SEATA_CONFIG_NAME | registry |
seataEnv | SEATA_ENV | 空值 |
默认配置: registry.conf
通过JVM参数: -DseataEnv=test 指定的配置文件: registry-test.conf
配置中心的配置可以放在很多个地方,例如下图的文件,zk,etcd等。 选择配置中心的形式后,就需要根据选择的类型做参数配置。每种配置中心需要的参数都不一样, 例如文件配置中心只需要: 文件类型=文件,文件名=file.conf 。 而zookeeper就需要指定服务器地址,会话超时时间,连接超时时间 等
基础配置
文件配置中心的基础配置:
配置类型 | 配置名称 | 含义 | 必须 | 类型 |
---|---|---|---|---|
通用 | conf.type | 配置中心的文件类型 ,nacos,consul,apollo,zk,etcd3,file 其中之一 | 是 | string |
nacos | config.nacos.serverAddr | 服务器地址, 例如: localhost | 是 | string |
nacos | config.nacos.namespace | 命名空间,例如: public | 是 | string |
nacos | config.nacos.group | 核心配置文件名称 | 是 | string |
nacos | config.nacos.cluster | 集群名称, 例如: default | 是 | string |
nacos | config.nacos.username | 用户名 | 是 | string |
nacos | config.nacos.password | 密码 | 是 | string |
consul | config.consul.serverAddr | 服务器地址, 例如:127.0.0.1:8500 | 是 | string |
apollo | config.apollo.appId | app名称,例如: seata-server | 是 | string |
apollo | config.apollo.apolloMeta | 元数据,例如: http://localhost:8801 | 是 | string |
apollo | config.apollo.namespace | 命名空间,例如: application | 是 | string |
zookeeper | config.zk.serverAddr | 服务器地址,例如: 127.0.0.1:2181 | 是 | string |
zookeeper | config.zk.sessionTimeout | 会话超时时间, 单位: 毫秒 | 是 | int |
zookeeper | config.zk.connectTimeout | 连接超时时间, 单位: 毫秒 | 是 | int |
zookeeper | config.zk.username | 用户名 | 是 | string |
zookeeper | config.zk.password | 密码 | 是 | string |
etcd | config.etcd3.serverAddr | 服务器地址, 例如: http://localhost:2379 | 是 | string |
file | config.file.name | 核心配置文件名称,例如: file.conf | 是 | string |
核心配置
配置名称 | 类型 | 默认值 | 必须 | 含义 |
---|---|---|---|---|
transport.type | string | TCP | 是 | worker线程的名称 |
transport.server | string | NIO | 是 | 传输方式, 取值范围: NIO,NATIVE |
transport.heartbeat | boolean | true | 是 | 是否启用心跳检查 |
transport.enableClientBatchSendRequest | boolean | true | 是 | 是否启用客户端批量发送请求 |
transport.threadFactory.bossThreadPrefix | string | NettyBoss | 否 | boss线程的名称 |
transport.threadFactory.workerThreadPrefix | string | NettyServerNIOWorker | 是 | worker线程的名称 |
transport.threadFactory.serverExecutorThreadPrefix | string | 无 | 是 | 服务执行器线程前缀, 目前版本无意义 |
transport.threadFactory.clientWorkerThreadPrefix | string | NettyClientWorkerThread | 否 | 服务执行器线程前缀 |
transport.threadFactory.clientSelectorThreadPrefix | string | NettyClientSelector | 否 | 客户端选择器的线程前缀 |
transport.threadFactory.clientSelectorThreadSize | int | 1 | 否 | 客户端选择器的线程大小 |
transport.threadFactory.shareBossWorker | boolean | 无 | 是 | 是否共享boss和worker的线程池,目前版本无意义 |
transport.threadFactory.shutdown.wait | int | 3 | 否 | 应用关闭时调用,配置中心关闭后,等待的时间 |
transport.threadFactory.bossThreadSize | int | 1 | 是 | boss线程池的数量 |
transport.threadFactory.workerThreadSize | string/int | CPU核数*2 | 否 | 为空或者是default是一样的, 也可以指定数字 |
transport.serialization | string | SEATA | 是 | 序列化的方式: 可选值: SEATA,PROTOBUF,KRYO,FST.(1.3.0还未支持HESSIAN, 下个版本会修复) |
transport.compressor | string | NONE | 是 | 压缩方式: NONE,GZIP,ZIP,SEVENZ,BZIP2,LZ4 |
transport.threadFactory.bossThreadSize | int | 1 | 是 | boss线程池的数量 |
service.vgroupMapping.my_test_tx_group | string | 无 | 是 | 传输服务组的映射, 创建GlobalTransactionScanner时指定分组名称,例如指定分组名称为my_test_tx_group |
service.default.grouplist | string | 无 | 是 | 服务默认组 |
service.enableDegrade | string | 无 | 是 | 当前版本不支持 |
service.disableGlobalTransaction | string | false | 否 | 是否禁用全局事物 |
client.rm.asyncCommitBufferLimit | int | 10000 | 是 | 二阶段异步提交的缓冲区大小 |
client.rm.lock.retryPolicyBranchRollbackOnConflict | boolean | true | 否 | 冲突时的回滚策略,设置为false时,如果发生了回滚冲突会进行重试重试 |
client.rm.lock.retryInterval | int | 10 | 否 | 重试间隔的毫秒数 |
client.rm.lock.retryTimes | int | 30 | 否 | 重试最大次数 |
client.rm.reportRetryCount | int | 10 | 否 | |
client.rm.tableMetaCheckEnable | boolean | false | 是 | 是否启用表的元数据检查,如果开启,则会开启一个定时器,每60秒执行一次,更新表元数据缓存Map的所有表的结构 |
client.rm.sqlParserType | string | druid | 是 | SQL解析器类型, (1.4.0的属性) |
client.rm.reportSuccessEnable | boolean | false | 否 | saga 模式是否报告成功状态 |
client.rm.sagaBranchRegisterEnable | boolean | false | 否 | saga模式是否启用分支注册(1.4.0) |
client.tm.commitRetryCount | int | false | 否 | 全局事物提交的最大重试次数 |
client.tm.rollbackRetryCount | int | false | 否 | 全局事物回滚的最大重试次数 |
client.undo.dataValidation | boolean | true | 否 | 二阶段回滚时,是否验证后置镜像与当前数据的一致性(避免脏写,一定要开启) |
client.undo.logSerialization | string | jackson | 否 | 回滚日志序列化方式 |
client.undo.logTable | string | undo_log | 否 | 回滚日志的表名称 |
client.log.exceptionRate | int | 100 | 否 | 随机打印调用栈的最大比例 |