worker-thread-prefix = “NettyServerNIOWorker”
server-executor-thread-prefix = “NettyServerBizHandler”
share-boss-worker = false
client-selector-thread-prefix = “NettyClientSelector”
client-selector-thread-size = 1
client-worker-thread-prefix = “NettyClientWorkerThread”
netty boss thread size,will not be used for UDT
boss-thread-size = 1
#auto default pin or 8
worker-thread-size = 8
}
shutdown {
when destroy server, wait seconds
wait = 3
}
serialization = “seata”
compressor = “none”
}
service {
#vgroup->rgroup
vgroup_mapping.my_test_tx_group = “fsp_ex_group”
#only support single node
default.grouplist = “127.0.0.1:8091”
#degrade current not support
enableDegrade = false
#disable
disable = false
#unit ms,s,m,h,d represents milliseconds, seconds, minutes, hours, days, default permanent
max.commit.retry.timeout = “-1”
max.rollback.retry.timeout = “-1”
#若报配置异常则加上下面一句配置即可
disableGlobalTransaction=false
}
client {
async.commit.buffer.limit = 10000
lock {
retry.internal = 10
retry.times = 30
}
report.retry.count = 5
tm.commit.retry.count = 1
tm.rollback.retry.count = 1
}
transaction log store
store {
store mode: file、db
mode = “db”
file store
file {
dir = “sessionStore”
branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
max-branch-session-size = 16384
globe session size , if exceeded throws exceptions
max-global-session-size = 512
file buffer size , if exceeded allocate new buffer
file-write-buffer-cache-size = 16384
when recover batch read size
session.reload.read_size = 100
async, sync
flush-disk-mode = async
}
database store
db {
the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp) etc.
datasource = “dbcp”
mysql/oracle/h2/oceanbase etc.
db-type = “mysql”
driver-class-name = “com.mysql.jdbc.Driver”
url = “jdbc:mysql://localhost:3306/seata”
user = “root”
password = “123456”
min-conn = 1
max-conn = 3
global.table = “global_table”
branch.table = “branch_table”
lock-table = “lock_table”
query-limit = 100
}
}
lock {
the lock store mode: local、remote
mode = “remote”
local {
store locks in user’s database
}
remote {
store locks in the seata’s server
}
}
recovery {
#schedule committing retry period in milliseconds
committing-retry-period = 1000
#schedule asyn committing retry period in milliseconds
asyn-committing-retry-period = 1000
#schedule rollbacking retry period in milliseconds
rollbacking-retry-period = 1000
#schedule timeout retry period in milliseconds
timeout-retry-period = 1000
}
transaction {
undo.data.validation = true
undo.log.serialization = “jackson”
undo.log.save.days = 7
#schedule delete expired undo_log in milliseconds
undo.log.delete.period = 86400000
undo.log.table = “undo_log”
}
metrics settings
metrics {
enabled = false
registry-type = “compact”
multi exporters use comma divided
exporter-list = “prometheus”
exporter-prometheus-port = 9898
}
support {
spring
spring {
auto proxy the DataSource bean
datasource.autoproxy = false
}
}
b.registry.conf修改
registry {
file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = “file”
nacos {
serverAddr = “localhost”
namespace = “”
cluster = “default”
}
eureka {
serviceUrl = “http://localhost:8761/eureka”
application = “default”
weight = “1”
}
redis {
serverAddr = “localhost:6379”
db = “0”
}
zk {
cluster = “default”
serverAddr = “127.0.0.1:2181”
session.timeout = 6000
connect.timeout = 2000
}
consul {
cluster = “default”
serverAddr = “127.0.0.1:8500”
}
etcd3 {
cluster = “default”
serverAddr = “http://localhost:2379”
}
sofa {
serverAddr = “127.0.0.1:9603”
application = “default”
region = “DEFAULT_ZONE”
datacenter = “DefaultDataCenter”
cluster = “default”
group = “SEATA_GROUP”
addressWaitTime = “3000”
}
file {
name = “file.conf”
}
}
config {
file、nacos 、apollo、zk、consul、etcd3
type = “file”
nacos {
serverAddr = “localhost”
namespace = “”
}
consul {
serverAddr = “127.0.0.1:8500”
}
apollo {
app.id = “seata-server”
apollo.meta = “http://192.168.1.204:8801”
}
zk {
serverAddr = “127.0.0.1:2181”
session.timeout = 6000
connect.timeout = 2000
}
etcd3 {
serverAddr = “http://localhost:2379”
}
file {
name = “file.conf”
}
}
3.创建seata数据库(mysql) 将seata->conf->db_store.sql放到数据库中运行即可
4.到bin目录下找到seata-server.bat运行即可 如下即为成功运行:
a.下载地址:https://github.com/alibaba/nacos/releases
b.修改application.properties文件(将数据库对应配置注释打开即可)
c.找到startup.cmd编辑里面的将set MODE="cluster"一行改成set MODE=“standalone”
d.点击startup.cmd运行即可,如下即为成功:
e.访问localhost:8848即可 默认账号密码都是:nacos
1.项目结构
account-service:负责对用户余扣减
business-service:负责完成下单的逻辑,包含 2 个主要的步骤,就是对库存服务和订单服务的远程调用
order-service:负责完成保存用户订单的操作
storage-service:负责完成对库存的扣减
2.各模块主要代码展示:
account-service
@Service
public class AccountServiceImpl implements AccountService {
@Autowired
private AccountTblMapper accountTblMapper ;
private static Logger logger = LoggerFactory.getLogger(AccountServiceImpl.class) ;
@Transactional
@Override
public void debit(String userId, int money) {
logger.info(“开始扣减用户:{}的余额,数量为:{}”,userId ,money);
//1 查询数据库里面的账户
AccountTbl accountTbl = accountTblMapper.selectOne(new LambdaQueryWrapper().
eq(AccountTbl::getUserId, userId));
if(accountTbl==null){
throw new IllegalArgumentException(“此账号不存在”) ;
}
//2 扣减的操作
int idleMoney = accountTbl.getMoney() - money ;
// 3 库存的校验
if(idleMoney<0){
throw new RuntimeException(“库存不足”) ;
}
//4 设置到账户里面
accountTbl.setMoney(idleMoney);
//5 保存到数据库里里面
accountTblMapper.updateById(accountTbl) ;
if(“SXT_USER_2”.equals(userId)){
throw new RuntimeException(“不想成功”) ;
}
}
}
####Pom文件
com.baomidou
mybatis-plus-boot-starter
3.3.0
mysql
mysql-connector-java
business-service
@Service
public class BusinessServiceImpl implements BusinessService {
private static Logger logger = LoggerFactory.getLogger(BusinessServiceImpl.class) ;
@Autowired
private StorageServiceApi storageServiceApi ;
@Autowired
private OrderServiceApi orderServiceApi ;
@Override
public void purchase(String userId, String productNo, int count) {
logger.info(“准备下单,用户{},商品{},数量{}”,userId ,productNo ,count);
// 1 远程调用库存服务–> 库存的扣减f
storageServiceApi.deduct(productNo, count);
// 2 远程调用订单服务–>订单的新增
最后,附一张自己面试前准备的脑图:
面试前一定少不了刷题,为了方便大家复习,我分享一波个人整理的面试大全宝典
- Java核心知识整理
- Spring全家桶(实战系列)
Step3:刷题
既然是要面试,那么就少不了刷题,实际上春节回家后,哪儿也去不了,我自己是刷了不少面试题的,所以在面试过程中才能够做到心中有数,基本上会清楚面试过程中会问到哪些知识点,高频题又有哪些,所以刷题是面试前期准备过程中非常重要的一点。
以下是我私藏的面试题库:
很多人感叹“学习无用”,实际上之所以产生无用论,是因为自己想要的与自己所学的匹配不上,这也就意味着自己学得远远不够。无论是学习还是工作,都应该有主动性,所以如果拥有大厂梦,那么就要自己努力去实现它。
最后祝愿各位身体健康,顺利拿到心仪的offer!
// 1 远程调用库存服务–> 库存的扣减f
storageServiceApi.deduct(productNo, count);
// 2 远程调用订单服务–>订单的新增
最后,附一张自己面试前准备的脑图:
[外链图片转存中…(img-4uzorYV1-1714150294171)]
面试前一定少不了刷题,为了方便大家复习,我分享一波个人整理的面试大全宝典
- Java核心知识整理
[外链图片转存中…(img-KTayCHfH-1714150294172)]
- Spring全家桶(实战系列)
[外链图片转存中…(img-tFGdVlZj-1714150294172)]
Step3:刷题
既然是要面试,那么就少不了刷题,实际上春节回家后,哪儿也去不了,我自己是刷了不少面试题的,所以在面试过程中才能够做到心中有数,基本上会清楚面试过程中会问到哪些知识点,高频题又有哪些,所以刷题是面试前期准备过程中非常重要的一点。
以下是我私藏的面试题库:
[外链图片转存中…(img-IgoD5bB1-1714150294173)]
很多人感叹“学习无用”,实际上之所以产生无用论,是因为自己想要的与自己所学的匹配不上,这也就意味着自己学得远远不够。无论是学习还是工作,都应该有主动性,所以如果拥有大厂梦,那么就要自己努力去实现它。
最后祝愿各位身体健康,顺利拿到心仪的offer!