seata-server

seata-server

  • 文章使用seata版本1.3,nacos版本1.3
    • 1.修改配置文件seata\conf\file.conf
    • 2.修改配置文件seata\conf\registry.conf
    • 3.将seata-server配置文件注册进nacos
    • 4.客户端
  • 总结


文章使用seata版本1.3,nacos版本1.3

都是直接在Windows上运行的:

1.修改配置文件seata\conf\file.conf

这里就不改了,因为直接注册进nacos,从nacos中取配置(示例):

2.修改配置文件seata\conf\registry.conf

代码如下(示例):
seata-server_第1张图片

#修改注册模式
registry {
     
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "nacos"
#注册地址
  nacos {
     
    application = "seata-server"
    serverAddr = "127.0.0.1:8848"
    group = "SEATA_GROUP"
    cluster = "default"
    username = "nacos"
    password = "nacos"
  }

3.将seata-server配置文件注册进nacos

修改registry.conf(示例):

#修改配置模式
config {
     
  # file、nacos 、apollo、zk、consul、etcd3
  type = "nacos"
#修改配置中心地址
nacos {
     
    serverAddr = "127.0.0.1:8848"
    group = "SEATA_GROUP"
    username = "nacos"
    password = "nacos"
  }

github获取config.txt
seata-server_第2张图片
seata-server_第3张图片

github获取nacos-config.sh
seata-server_第4张图片

新建文件夹script,放入nacos-config.sh
config.txt放在seata根目录下

seata-server_第5张图片

seata-server_第6张图片

也可以直接双击
当在nacos中看到配置代表上传成功

seata-server_第7张图片

启动nacos
此处nacos配置存储模式为mysql
启动seata
seata需要cmd加命令行参数
seata-server.bat -h 127.0.0.1 -p 8091

4.客户端

3个服务
一个订单
一个库存
一个consumer(通过feign调用订单和库存)
pom和yml配置基本大同小异(复制粘贴就好):
seata-server_第8张图片
pom

	
        
            com
            common-api
            0.0.1-SNAPSHOT
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            2.1.4
        
        
            mysql
            mysql-connector-java
        
        
        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-seata
            
                
                
                    seata-all
                    io.seata
                
                
                    io.seata
                    seata-spring-boot-starter
                
            
        
        
        
            io.seata
            seata-spring-boot-starter
            1.3.0
        
        
        
            org.springframework.cloud
            spring-cloud-starter-openfeign
        
        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-nacos-discovery
        
        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-nacos-config
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-actuator
        
        
            org.springframework.boot
            spring-boot-devtools
            runtime
            true
        
    

yml

server:
  port: 8002
spring:
  application:
    name: seata-storage
  #注册nacos
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848
        register-enabled: true
      config:
        server-addr: 127.0.0.1:8848
        enabled: true
        file-extension: yaml

  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/seata_storage?serverTimezone=UTC
    username: root
    password: 123
    type: com.alibaba.druid.pool.DruidDataSource

#seata配置
seata:
  enabled: true
  application-id: ${
     spring.application.name}
  tx-service-group: ${
     spring.application.name}-tx-group
  config:
    type: nacos
    nacos:
      server-addr: 127.0.0.1:8848
      group: SEATA_GROUP
      username: nacos
      password: nacos
  registry:
    type: nacos
    nacos:
      application: seata-server
      server-addr: 127.0.0.1:8848
      group: SEATA_GROUP
      username: nacos
      password: nacos

  service:
    vgroup-mapping:
      seata-order-tx-group: default

mybatis:
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.ccss.entity

核心代码@GlobalTransactional开启全局事务
这里库存调用设置了异常,通过打断点会发现undo_log表记录的前置镜像和后置镜像
seata-server_第9张图片
表结构
seata-server_第10张图片


总结

篇幅过长,不上代码了,环境搭建难,用起来就一个注解,总结一些理论

  1. AT/TCC/Saga事务模式
  2. 读写隔离
  3. 2pc,3pc
  4. base理论

你可能感兴趣的:(seata-server)