首页 > 其他分享 >Seata

Seata

时间:2023-05-13 17:23:49浏览次数:32  
标签:Seata DEFAULT server client transport NULL store

Seata

Nacos下的Seata

下载Seata
docker pull seata:1.4.1
启动Seata
docker run -d --name seata-prod --restart=always -p 28091:8091 -v /seata-prod/registry.conf:/seata-server/resources/registry.conf -v /seata-prod/logs:/root/logs seataio/seata-server:1.4.2

修改Seata配置文件

修改registry.conf
registry {
  type = "nacos"

  nacos {
    application = "seata-server"
    serverAddr = [nacos address]
    group = "SEATA_GROUP"
    namespace = [nacos namespace]
    cluster = "default"
    username = [nacos username]
    password = [name password]
  }
}

config {
  type = "nacos"

  nacos {
    serverAddr = [nacos address]
    namespace = [nacos namespace]
    group = "SEATA_GROUP"
    username = [nacos username]
    password = [name password]
    dataId = "seataServer.properties"
  }
}
新增seataServer.properties
#For details about configuration items, see https://seata.io/zh-cn/docs/user/configurations.html
#Transport configuration, for client and server
transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableTmClientBatchSendRequest=false
transport.enableRmClientBatchSendRequest=true
transport.enableTcServerBatchSendResponse=false
transport.rpcRmRequestTimeout=30000
transport.rpcTmRequestTimeout=30000
transport.rpcTcRequestTimeout=30000
transport.threadFactory.bossThreadPrefix=NettyBoss
transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker
transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler
transport.threadFactory.shareBossWorker=false
transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector
transport.threadFactory.clientSelectorThreadSize=1
transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread
transport.threadFactory.bossThreadSize=1
transport.threadFactory.workerThreadSize=default
transport.shutdown.wait=3
transport.serialization=seata
transport.compressor=none

#Transaction routing rules configuration, only for the client
# 事务分组。需要与项目中的事务分组配置保持一致
service.vgroupMapping.[application name]-fescar-service-group=default

#Transaction rule configuration, only for the client
client.rm.asyncCommitBufferLimit=10000
client.rm.lock.retryInterval=10
client.rm.lock.retryTimes=30
client.rm.lock.retryPolicyBranchRollbackOnConflict=true
client.rm.reportRetryCount=5
client.rm.tableMetaCheckEnable=false
client.rm.tableMetaCheckerInterval=60000
client.rm.sqlParserType=druid
client.rm.reportSuccessEnable=false
client.rm.sagaBranchRegisterEnable=false
client.rm.sagaJsonParser=fastjson
client.rm.tccActionInterceptorOrder=-2147482648
client.tm.commitRetryCount=5
client.tm.rollbackRetryCount=5
client.tm.defaultGlobalTransactionTimeout=60000
client.tm.degradeCheck=false
client.tm.degradeCheckAllowTimes=10
client.tm.degradeCheckPeriod=2000
client.tm.interceptorOrder=-2147482648
client.undo.dataValidation=true
client.undo.logSerialization=jackson
client.undo.onlyCareUpdateColumns=true
server.undo.logSaveDays=7
server.undo.logDeletePeriod=86400000
client.undo.logTable=undo_log
client.undo.compress.enable=true
client.undo.compress.type=zip
client.undo.compress.threshold=64k
#For TCC transaction mode
tcc.fence.logTableName=tcc_fence_log
tcc.fence.cleanPeriod=1h

#Log rule configuration, for client and server
log.exceptionRate=100

#Transaction storage configuration, only for the server. The file, DB, and redis configuration values are optional.
# 使用db进行事务存储
store.mode=db
store.lock.mode=db
store.session.mode=db
#Used for password encryption
store.publicKey=


#These configurations are required if the `store mode` is `db`. If `store.mode,store.lock.mode,store.session.mode` are not equal to `db`, you can remove the configuration block.
store.db.datasource=druid
store.db.dbType=mysql
# Mysql 8.0版本以下请使用com.mysql.jdbc.Driver作为驱动
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://[mysql url]/seata?rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false
# 填写你的mysql用户
store.db.user=[mysql user]
# 填写你的mysql密码
store.db.password=[mysql passwrod]
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.distributedLockTable=distributed_lock
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000

#Transaction rule configuration, only for the server
server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000
server.maxCommitRetryTimeout=-1
server.maxRollbackRetryTimeout=-1
server.rollbackRetryTimeoutUnlockEnable=false
server.distributedLockExpireTime=10000
server.xaerNotaRetryTimeout=60000
server.session.branchAsyncQueueSize=5000
server.session.enableBranchAsyncRemove=true

#Metrics configuration, only for the server
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898
新增seata数据库

新增在seataServer.properties配置文件中配置的数据库seata,同时新增多张数据表

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for branch_table
-- ----------------------------
DROP TABLE IF EXISTS `branch_table`;
CREATE TABLE `branch_table` (
  `branch_id` bigint(20) NOT NULL,
  `xid` varchar(128) NOT NULL,
  `transaction_id` bigint(20) DEFAULT NULL,
  `resource_group_id` varchar(32) DEFAULT NULL,
  `resource_id` varchar(256) DEFAULT NULL,
  `branch_type` varchar(8) DEFAULT NULL,
  `status` tinyint(4) DEFAULT NULL,
  `client_id` varchar(64) DEFAULT NULL,
  `application_data` varchar(2000) DEFAULT NULL,
  `gmt_create` datetime(6) DEFAULT NULL,
  `gmt_modified` datetime(6) DEFAULT NULL,
  PRIMARY KEY (`branch_id`),
  KEY `idx_xid` (`xid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ----------------------------
-- Table structure for distributed_lock
-- ----------------------------
DROP TABLE IF EXISTS `distributed_lock`;
CREATE TABLE `distributed_lock` (
  `lock_key` char(20) NOT NULL,
  `lock_value` varchar(20) NOT NULL,
  `expire` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`lock_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ----------------------------
-- Table structure for global_table
-- ----------------------------
DROP TABLE IF EXISTS `global_table`;
CREATE TABLE `global_table` (
  `xid` varchar(128) NOT NULL,
  `transaction_id` bigint(20) DEFAULT NULL,
  `status` tinyint(4) NOT NULL,
  `application_id` varchar(32) DEFAULT NULL,
  `transaction_service_group` varchar(128) DEFAULT NULL,
  `transaction_name` varchar(128) DEFAULT NULL,
  `timeout` int(11) DEFAULT NULL,
  `begin_time` bigint(20) DEFAULT NULL,
  `application_data` varchar(2000) DEFAULT NULL,
  `gmt_create` datetime DEFAULT NULL,
  `gmt_modified` datetime DEFAULT NULL,
  PRIMARY KEY (`xid`),
  KEY `idx_status_gmt_modified` (`status`,`gmt_modified`),
  KEY `idx_transaction_id` (`transaction_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ----------------------------
-- Table structure for lock_table
-- ----------------------------
DROP TABLE IF EXISTS `lock_table`;
CREATE TABLE `lock_table` (
  `row_key` varchar(128) NOT NULL,
  `xid` varchar(128) DEFAULT NULL,
  `transaction_id` bigint(20) DEFAULT NULL,
  `branch_id` bigint(20) NOT NULL,
  `resource_id` varchar(256) DEFAULT NULL,
  `table_name` varchar(32) DEFAULT NULL,
  `pk` varchar(36) DEFAULT NULL,
  `status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0:locked ,1:rollbacking',
  `gmt_create` datetime DEFAULT NULL,
  `gmt_modified` datetime DEFAULT NULL,
  PRIMARY KEY (`row_key`),
  KEY `idx_status` (`status`),
  KEY `idx_branch_id` (`branch_id`),
  KEY `idx_xid` (`xid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

SET FOREIGN_KEY_CHECKS = 1;

对目标服务的数据库新增数据库表:un_log

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for undo_log
-- ----------------------------
DROP TABLE IF EXISTS `undo_log`;
CREATE TABLE `undo_log`  (
  `branch_id` bigint(20) NOT NULL COMMENT '分支事务ID',
  `xid` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '全局事务ID',
  `context` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '上下文',
  `rollback_info` longblob NOT NULL COMMENT '回滚信息',
  `log_status` int(11) NOT NULL COMMENT '状态,0正常,1全局已完成',
  `log_created` datetime(6) NOT NULL COMMENT '创建时间',
  `log_modified` datetime(6) NOT NULL COMMENT '修改时间',
  UNIQUE INDEX `ux_undo_log`(`xid`, `branch_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = 'AT transaction mode undo table' ROW_FORMAT = Compact;

SET FOREIGN_KEY_CHECKS = 1;

修改application.yml配置文件

seata:
  registry:
    type: nacos
    nacos:
      application: seata-server
      server-addr: ${spring.cloud.nacos.discovery.server-addr}
      group: SEATA_GROUP
      namespace: ${spring.cloud.nacos.discovery.namespace}
  config:
    type: nacos
    nacos:
      server-addr: ${spring.cloud.nacos.discovery.server-addr}
      group: ${seata.registry.nacos.group}
      namespace: ${spring.cloud.nacos.discovery.namespace}
      dataId: seataServer.properties

标签:Seata,DEFAULT,server,client,transport,NULL,store
From: https://www.cnblogs.com/duolaa/p/17397737.html

相关文章

  • SpringCloud之Seata(一)
    思维导图1.概述1.1概念Seata是一款开源的分布式事务解决方案,提供高性能和简单易用的分布式事务服务。2.事务概述2.1角色TC((TransactionCoordinator)):事务协调者:维护全局和分支事务的状态,驱动全局事务提交或回滚。TM(TransactionManager):事务管理器:定义全局事务的范围:开......
  • SEATA-1.6.1
    一、简介本文主要介绍分布式事务框架seata(seata版本1.6.1)的window版本安装以及springboot与seata的整合的事务回滚案例;seata的官方文档路径:http://seata.io/zh-cn/本文介绍的方式是AT模式,采用的中间件是nacos,存储类型为db模式;本文默认你已会nacos的安装,如果不会请移步nacos......
  • Seata分布式事务
    Seata目录旁边可以查询具体的目录结构和跳转一.分布式事务 1.原子性(atomicity):个事务是一个不可分割的工作单位,事务中包括的诸操作要么都做,要么都不做。  2.一致性(consistency):事务必须是使数据库从一个一致性状态变到另一个一致性状态,事务的中间状态不能被观察到的。  ......
  • Seata:连接数据与应用
    作者:季敏(清铭)Seata开源社区创始人,分布式事务团队负责人。本文主要介绍分布式事务从内部到商业化和开源的演进历程,Seata社区当前进展和未来规划。Seata是一款开源的分布式事务解决方案,旨在为现代化微服务架构下的分布式事务提供解决方案。Seata提供了完整的分布式事务解决方案,包......
  • seata学习AT模式
    注意点这里版本seata1.4.2(启动直接bin目录下面bat文件启动)数据库代理enable-auto-data-source-proxy这个配置默认开启(默认开启,配置相关配置就可以使用seata了),切换其他的可以自己配置。版本问题官网参考具体教程1.背景介绍Seata是一款开源的分布式事务解决......
  • Springboot整合Seata实现分布式事务
    前言Seata是一款开源的分布式事务解决方案,致力于提供高性能和简单易用的分布式事务服务。Seata将为用户提供了AT、TCC、SAGA和XA事务模式,为用户打造一站式的分布式解决方案。Seata配置非常灵活,支持多种注册中心、配置来源(配置中心)和持久化方式。本文选择eureka作注册中......
  • 浅谈分布式事务-Seata
    传统的单机事务。在传统数据库事务中,必须要满足四个原则(ACID):ACID:Atomic(原子性)、Consistency(一致性)、Isolation(隔离性)和Durability(持久性)原子性(Atomicity)一个事务(transact......
  • Seata锁等待超时问题排查
    生产环境,一个简单的事务方法,提交失败,报Globallockwaittimeout伪代码如下:@GlobalTransactional(rollbackFor=Exception.class,timeoutMills=30000,lockRetryInter......
  • docker安装seata1.4.2
    dockerrun-d--restart=always--nameseata-p8091:8091-v/root/seata/seata-server:/seata-server-eSEATA_IP=127.0.0.1-eSEATA_PORT=8091seataio/seata-serv......
  • SpringCloud——SpringCloud Alibaba Seata 原理与实战
    摘要主要讲解是分布式事务指事务的操作位于不同的节点上,需要保证事务的AICD特性。分布式事务顾名思义就是要在分布式系统中实现事务,它其实是由多个本地事务组合而成。对于......