seata-server 1.3.0整合nacos,使用nacos做注册和配置中心
前言
关于seata版本的选择和更详细的安装,可以参考 SpringCloud Alibaba之Seata入门及踩坑
本篇博客是整合nacos,nacos直接下载安装解压运行就可以了。
seata的下载:
可以去seata官网上面点击下载,然后找到对应版本去github上面下载,但是github上面懂得,速度老慢了。
也可以去sourceforge-seata上面下载,虽然也慢,起码不会跟github一样偶尔找不到的好。
vxxx.zip和vxxx.tar.gz是对应系统和版本的源码,也可以下载下来,因为一些文件要从里面拿
seata-server-x.x.x.zip和tar.gz是对应系统和版本的服务器,拿过来直接用的,必须下,源码随意
我自己下载下来几个版本(源码只有1.4.0的),可以瞅一眼,这个云也许会快一点吧...
https://wwa.lanzoui.com/b010hbq8j
密码:seata
seata-server安装
解压下载下来seata-server。打开
/seata/conf文件夹,其中主要修改的是registry.conf和fiel.conf,由于我们基于nacos,这里就不用管file.conf了。下面先将registry.conf备份,然后修改为:registry {
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "127.0.0.1:8848"
group = "SEATA_GROUP"
namespace = ""
cluster = "default"
username = "nacos"
password = "nacos"
}
} config {
type = "nacos"
nacos {
serverAddr = "127.0.0.1:8848"
namespace = ""
group = "SEATA_GROUP"
username = "nacos"
password = "nacos"
}
}
其中的含义:
- registry:服务器要注册到nacos的位置(命名空间、集群什么的)。
- config:seata服务器配置,这里需要去nacos上面拿配置,那么nacos上面没有,所以我们需要推上去。
解压下载下来的源码,打开文件夹
/script/config-center下的config.txt,也可以直接复制。transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableClientBatchSendRequest=false
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
service.vgroupMapping.my_test_tx_group=default
service.default.grouplist=127.0.0.1:8091
service.enableDegrade=false
service.disableGlobalTransaction=false
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.sqlParserType=druid
client.rm.reportSuccessEnable=false
client.rm.sagaBranchRegisterEnable=false
client.tm.commitRetryCount=5
client.tm.rollbackRetryCount=5
client.tm.defaultGlobalTransactionTimeout=60000
client.tm.degradeCheck=false
client.tm.degradeCheckAllowTimes=10
client.tm.degradeCheckPeriod=2000
store.mode=file
store.file.dir=file_store/data
store.file.maxBranchSessionSize=16384
store.file.maxGlobalSessionSize=512
store.file.fileWriteBufferCacheSize=16384
store.file.flushDiskMode=async
store.file.sessionReloadReadSize=100
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true
store.db.user=username
store.db.password=password
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
store.redis.host=127.0.0.1
store.redis.port=6379
store.redis.maxConn=10
store.redis.minConn=1
store.redis.database=0
store.redis.password=null
store.redis.queryLimit=100
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
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.log.exceptionRate=100
transport.serialization=seata
transport.compressor=none
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898
主要修改其中的:
service.vgroupMapping.my_test_tx_group=default
# 其中my_test_tx_group是可以自定义的且之后要与seata客户端中相匹配 store.mode=file
# 修改为db,下面修改到对应数据库的信息 store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true
store.db.user=username
store.db.password=password
打开源码中的
script/config-center/nacos下的nacos-config.sh,也可以从下面复制。#!/usr/bin/env bash
# Copyright 1999-2019 Seata.io Group.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at、
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. while getopts ":h:p:g:t:u:w:" opt
do
case $opt in
h)
host=$OPTARG
;;
p)
port=$OPTARG
;;
g)
group=$OPTARG
;;
t)
tenant=$OPTARG
;;
u)
username=$OPTARG
;;
w)
password=$OPTARG
;;
?)
echo " USAGE OPTION: $0 [-h host] [-p port] [-g group] [-t tenant] [-u username] [-w password] "
exit 1
;;
esac
done if [[ -z ${host} ]]; then
host=localhost
fi
if [[ -z ${port} ]]; then
port=8848
fi
if [[ -z ${group} ]]; then
group="SEATA_GROUP"
fi
if [[ -z ${tenant} ]]; then
tenant=""
fi
if [[ -z ${username} ]]; then
username=""
fi
if [[ -z ${password} ]]; then
password=""
fi nacosAddr=$host:$port
contentType="content-type:application/json;charset=UTF-8" echo "set nacosAddr=$nacosAddr"
echo "set group=$group" failCount=0
tempLog=$(mktemp -u)
function addConfig() {
curl -X POST -H "${contentType}" "http://$nacosAddr/nacos/v1/cs/configs?dataId=$1&group=$group&content=$2&tenant=$tenant&username=$username&password=$password" >"${tempLog}" 2>/dev/null
if [[ -z $(cat "${tempLog}") ]]; then
echo " Please check the cluster status. "
exit 1
fi
if [[ $(cat "${tempLog}") =~ "true" ]]; then
echo "Set $1=$2 successfully "
else
echo "Set $1=$2 failure "
(( failCount++ ))
fi
} count=0
for line in $(cat $(dirname "$PWD")/config.txt | sed s/[[:space:]]//g); do
(( count++ ))
key=${line%%=*}
value=${line#*=}
addConfig "${key}" "${value}"
done echo "========================================================================="
echo " Complete initialization parameters, total-count:$count , failure-count:$failCount "
echo "=========================================================================" if [[ ${failCount} -eq 0 ]]; then
echo " Init nacos config finished, please start seata-server. "
else
echo " init nacos config fail. "
fi
可以直接修改下面这些,也可以执行时候使用参数形式给进去。
if [[ -z ${host} ]]; then
host=localhost
fi
if [[ -z ${port} ]]; then
port=8848
fi
if [[ -z ${group} ]]; then
group="SEATA_GROUP"
fi
if [[ -z ${tenant} ]]; then
tenant=""
fi
if [[ -z ${username} ]]; then
username=""
fi
if [[ -z ${password} ]]; then
password=""
fi
其中
tenant为命名空间,也即nacos上面的namespace。运行nacos,然后windows下可以安装
Git For Windows来运行sh文件将配置推上nacos。打开nacos,点击配置管理,和自己填写对应的命名空间(""默认为public),检查第二步中自定数据库和
service.vgroupMapping.my_test_tx_group。那么里面的数据库呢?MySQL中没有seata数据库啊。下面来手动新建。新建数据库seata(可以自己命名,nacos上面可以手动编辑的),新建三个表,sql代码官方也给出来了,在源码的
script/server/db下的mysql.sql,如下-- -------------------------------- The script used when storeMode is 'db' --------------------------------
-- the table to store GlobalSession data
CREATE TABLE IF NOT EXISTS `global_table`
(
`xid` VARCHAR(128) NOT NULL,
`transaction_id` BIGINT,
`status` TINYINT NOT NULL,
`application_id` VARCHAR(32),
`transaction_service_group` VARCHAR(32),
`transaction_name` VARCHAR(128),
`timeout` INT,
`begin_time` BIGINT,
`application_data` VARCHAR(2000),
`gmt_create` DATETIME,
`gmt_modified` DATETIME,
PRIMARY KEY (`xid`),
KEY `idx_gmt_modified_status` (`gmt_modified`, `status`),
KEY `idx_transaction_id` (`transaction_id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8; -- the table to store BranchSession data
CREATE TABLE IF NOT EXISTS `branch_table`
(
`branch_id` BIGINT NOT NULL,
`xid` VARCHAR(128) NOT NULL,
`transaction_id` BIGINT,
`resource_group_id` VARCHAR(32),
`resource_id` VARCHAR(256),
`branch_type` VARCHAR(8),
`status` TINYINT,
`client_id` VARCHAR(64),
`application_data` VARCHAR(2000),
`gmt_create` DATETIME(6),
`gmt_modified` DATETIME(6),
PRIMARY KEY (`branch_id`),
KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8; -- the table to store lock data
CREATE TABLE IF NOT EXISTS `lock_table`
(
`row_key` VARCHAR(128) NOT NULL,
`xid` VARCHAR(96),
`transaction_id` BIGINT,
`branch_id` BIGINT NOT NULL,
`resource_id` VARCHAR(256),
`table_name` VARCHAR(32),
`pk` VARCHAR(36),
`gmt_create` DATETIME,
`gmt_modified` DATETIME,
PRIMARY KEY (`row_key`),
KEY `idx_branch_id` (`branch_id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8;
运行
seata-server/bin/seata-server.bat,查看nacos上面服务管理中是否有对应seata-server服务启动。至此,seata-server服务端配置完成。
seata客户端准备与概况
在seata的提供者有了之后,我们需要来创建seata客户端。这里使用微服务模块的方式来配置。
注:在AT模式下,各自客户端中操作每个数据库中必须要有一个
undo_log表,创建脚本在源码script/client/at/db/mysql.sql,如下:-- for AT mode you must to init this sql for you business database. the seata server not need it.
CREATE TABLE IF NOT EXISTS `undo_log`
(
`branch_id` BIGINT(20) NOT NULL COMMENT 'branch transaction id',
`xid` VARCHAR(100) NOT NULL COMMENT 'global transaction id',
`context` VARCHAR(128) NOT NULL COMMENT 'undo_log context,such as serialization',
`rollback_info` LONGBLOB NOT NULL COMMENT 'rollback info',
`log_status` INT(11) NOT NULL COMMENT '0:normal status,1:defense status',
`log_created` DATETIME(6) NOT NULL COMMENT 'create datetime',
`log_modified` DATETIME(6) NOT NULL COMMENT 'modify datetime',
UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
) ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARSET = utf8 COMMENT ='AT transaction mode undo table';
由于篇幅过长,简单来描述测试过程就是:
- 建立两个独立的数据库
- 在两个提供者中对各自的数据库做插入或者更新操作。
- 在消费者调用的方法或者类上面注解
@GlobalTransactional - 在调用完提供者处理数据库的方法后,手动抛出异常。
- 数据库中完成回滚。
参考:
seata-server 1.3.0整合nacos,使用nacos做注册和配置中心的更多相关文章
- Spring Cloud入门-Nacos实现注册和配置中心(Hoxton版本)
文章目录 摘要 Nacos简介 使用Nacos作为注册中心 安装并运行Nacos 创建应用注册到Nacos 负载均衡功能 使用Nacos作为配置中心 创建nacos-config-client模块 在 ...
- 使用Alibaba的Nacos做为SpringCloud的注册和配置中心,并结合Sentinel+Nocos动态进行限流熔断
最近在学习阿里的Nacos组件以及Sentinel组件,折腾出了一个小demo. Git地址:https://github.com/yangzhilong/nacos-client 有兴趣的小伙伴可以 ...
- Spring Cloud实战 | 第十篇 :Spring Cloud + Seata 1.4.1 + Nacos1.4.0 整合实现微服务架构中逃不掉的话题分布式事务
Seata分布式事务在线体验地址:https://www.youlai.store 本篇完整源码地址:https://github.com/hxrui/youlai-mall 有想加入开源项目开发的童 ...
- SpringCloud实战 | 第三篇:SpringCloud整合Nacos实现配置中心
前言 随着eureka的停止更新,如果同时实现注册中心和配置中心需要SpringCloud Eureka和SpringCloud Config两个组件;配置修改刷新时需要SpringCloud Bus ...
- 配置中心Nacos(服务发现)
服务演变之路 单体应用架构 在刚开始的时候,企业的用户量.数据量规模都⽐较⼩,项⽬所有的功能模块都放在⼀个⼯程中编码.编译.打包并且部署在⼀个Tomcat容器中的架构模式就是单体应用架构,这样的架构既 ...
- .net5+nacos+ocelot 配置中心和服务发现实现
最近一段时间 因公司业务需要,需要使用.net5做一套微服务的接口,使用nacos 做注册中心和配置中心,ocelot做网关. 因为ocelot 支持的是consol和eureka,如果使用nacos ...
- spring cloud alibaba - Nacos 作为配置中心基础使用
1.简要说明 Nacos提供了作为配置中心的功能,只需要在Nacos的控制台页面添加配置,然后在项目中配置相应的"路径"就好. 主要分为几个步骤: 在Nacos控制台添加配置 在项 ...
- 5-18 Nacos配置中心 | RestTemplate
配置中心 什么是配置中心 所谓配置中心:将项目需要的配置信息保存在配置中心,需要读取时直接从配置中心读取,方便配置管理的微服务工具 我们可以将部分yml文件的内容保存在配置中心 一个微服务项目有很多子 ...
- 【Nacos】Springboot整合Nacos配置中心(二) 多环境配置
本篇随笔接上一篇文章:Springboot整合Nacos配置中心(一),主要记录Nacos多环境的配置的方法 Nacos多环境的配置 方法一: 1.在项目中的bootstrap.yaml文件中配置激活 ...
- Spring Cloud Alibaba 整合 Nacos 实现服务配置中心
在之前的文章 <Nacos 本地单机版部署步骤和使用> 中,大家应该了解了 Nacos 是什么?其中 Nacos 提供了动态配置服务功能 一.Nacos 动态配置服务是什么? 官方是这么说 ...
随机推荐
- 经典算法的Java实现
1.快速排序描述 1.每一轮排序选择一个基准点(pivot)进行分区 1.让小于基准点的元素进入一个分区,大于基准点的元素进入另一个分区 2.当分区完成时,基准点元素的位置就是其最终位置 2.在子分区 ...
- Linux curl brew命令详解
命令:curl 在Linux中curl是一个利用URL规则在命令行下工作的文件传输工具,可以说是一款很强大的http命令行工具.它支持文件的上传和下载,是综合传输工具,但按传统,习惯称url为下载工具 ...
- HTTPS 证书自动化运维:告别手动管理,迎接自动化时代
1. 引言 随着互联网的发展,网络安全变得越来越重要.HTTPS(Hypertext Transfer Protocol Secure)通过使用 SSL/TLS 协议加密数据传输,确保了用户与网站之间 ...
- 00-串口和SSH方式登录
登录 1.板载LED灯状态说明 USB转TTL模块准备(安装ch340驱动) a.USB转TTL模块的GND接到开发板GND b.USB转TTL模块的RX接到开发板TX c.USB转TTL模块的TX接 ...
- java集合中的迭代器Iterator和数组内置方法以及常见的报错
删除Map的中某一项报错 package part; import java.util.HashMap; import java.util.Set; public class Java01 { pub ...
- EIP和NAT结合如何实现统一公网出口IP
本文分享自天翼云开发者社区<EIP和NAT结合如何实现统一公网出口IP>,作者:j****n 通过EIP和NAT网关结合,为已绑定EIP的ECS实例统一公网出口IP,有利于更高效的管理互联 ...
- nvme磁盘故障注入方法
本文分享自天翼云开发者社区<nvme磁盘故障注入方法>,作者:曹****飞 在存储系统中,磁盘的故障是很可能出现的问题.存储软件的设计需要对故障进行处理,提高系统的健壮性.然而磁盘的故障是 ...
- 使用PhantomJS解决VUE项目无法被百度收录
一.安装PhantomJS 安装文章:https://www.cnblogs.com/robots2/p/17340143.html 二.编写脚本spider.js // spider.js 'use ...
- RocketMQ实战—9.营销系统代码初版
大纲 1.基于条件和画像筛选用户的业务分析和实现 2.全量用户促销活动数据模型分析以及创建操作 3.Producer和Consumer的工程代码实现 4.基于抽象工厂模式的消息推送实现 5.全量用户促 ...
- JavaScript 滚动条滚动到底部才触发按钮是否可用
应用代码片段: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...