Seata使用搭建笔记

1.服务端搭建,下载seata ,地址Releases · seata/seata · GitHubReleases · seata/seata · GitHubReleases · seata/seata · GitHub

2.解压安装,修改服务端配置文件

(1)修改register.conf

 

registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "nacos"

  nacos {
    application = "seata-server"
    serverAddr = "127.0.0.1:8848"
    group = "SEATA_GROUP"
    namespace = "4d8e2a2e-b59e-4a6b-80f7-301a98324675"
    cluster = "default"
    username = "nacos"
    password = "nacos"
  }
  eureka {
    serviceUrl = "http://localhost:8761/eureka"
    application = "default"
    weight = "1"
  }
  redis {
    serverAddr = "localhost:6379"
    db = 0
    password = ""
    cluster = "default"
    timeout = 0
  }
  zk {
    cluster = "default"
    serverAddr = "127.0.0.1:2181"
    sessionTimeout = 6000
    connectTimeout = 2000
    username = ""
    password = ""
  }
  consul {
    cluster = "default"
    serverAddr = "127.0.0.1:8500"
    aclToken = ""
  }
  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 = "nacos"

  nacos {
    serverAddr = "127.0.0.1:8848"
    namespace = "4d8e2a2e-b59e-4a6b-80f7-301a98324675"
    group = "SEATA_GROUP"
    username = "nacos"
    password = "nacos"
    dataId = "seata.properties"
  }
  consul {
    serverAddr = "127.0.0.1:8500"
    aclToken = ""
  }
  apollo {
    appId = "seata-server"
    ## apolloConfigService will cover apolloMeta
    apolloMeta = "http://192.168.1.204:8801"
    apolloConfigService = "http://192.168.1.204:8080"
    namespace = "application"
    apolloAccesskeySecret = ""
    cluster = "seata"
  }
  zk {
    serverAddr = "127.0.0.1:2181"
    sessionTimeout = 6000
    connectTimeout = 2000
    username = ""
    password = ""
    nodePath = "/seata/seata.properties"
  }
  etcd3 {
    serverAddr = "http://localhost:2379"
  }
  file {
    name = "file.conf"
  }
}
 

(2)修改file.conf

## transaction log store, only used in seata-server
transport {
  # tcp udt unix-domain-socket
  type = "TCP"
  #NIO NATIVE
  server = "NIO"
  #enable heartbeat
  heartbeat = true
  #thread factory for netty
  thread-factory {
    boss-thread-prefix = "NettyBoss"
    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
  vgroupMapping.my_test_tx_group = "default"
  #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"
}

client {
  async.commit.buffer.limit = 10000
  lock {
    retry.internal = 10
    retry.times = 30
  }
  report.retry.count = 5
}

store {
  ## store mode: file、db、redis
  mode = "db"
  ## rsa decryption public key
  publicKey = ""
  ## file store property
  file {
    ## store location dir
    dir = "sessionStore"
    # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
    maxBranchSessionSize = 16384
    # globe session size , if exceeded throws exceptions
    maxGlobalSessionSize = 512
    # file buffer size , if exceeded allocate new buffer
    fileWriteBufferCacheSize = 16384
    # when recover batch read size
    sessionReloadReadSize = 100
    # async, sync
    flushDiskMode = async
  }

  ## database store property
  db {
    ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp)/HikariDataSource(hikari) etc.
    datasource = "druid"
    ## mysql/oracle/postgresql/h2/oceanbase etc.
    dbType = "mysql"
    driverClassName = "com.mysql.jdbc.Driver"
    ## if using mysql to store the data, recommend add rewriteBatchedStatements=true in jdbc connection param
    url = "jdbc:mysql://127.0.0.1:3306/seata"
    user = "root"
    password = "123654"
    minConn = 5
    maxConn = 100
    globalTable = "global_table"
    branchTable = "branch_table"
    lockTable = "lock_table"
    queryLimit = 100
    maxWait = 5000
  }

  ## redis store property
  redis {
    ## redis mode: single、sentinel
    mode = "single"
    ## single mode property
    single {
      host = "127.0.0.1"
      port = "6379"
    }
    ## sentinel mode property
    sentinel {
      masterName = ""
      ## such as "10.28.235.65:26379,10.28.235.65:26380,10.28.235.65:26381"
      sentinelHosts = ""
    }
    password = ""
    database = "0"
    minConn = 1
    maxConn = 10
    maxTotal = 100
    queryLimit = 100
  }
}
 

 

(3).nacos增加配置文件seata.properties,用于对应register.conf的dataId

(4).先启动nacos,再启动seata,window启动 cmd到bin目录,执行(.\seata-server.bat -p 8091 -h 127.0.0.1 -m db)

 3.客户端配置

 seata:
  registry:
    type: nacos
    nacos:
      server-addr: 127.0.0.1:8848
      group: "SEATA_GROUP"
      namespace: "4d8e2a2e-b59e-4a6b-80f7-301a98324675"
      username: "nacos"
      password: "nacos"
spring:
  profiles:
    active: develop
  application:
    name: service-center
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848
        # 指定命名空间,如果不是public,那么必须指定命名空间的id,(服务管理根据这个id匹配服务列表,监控对应的健康服务)
        namespace: 4d8e2a2e-b59e-4a6b-80f7-301a98324675
         # 指定组
        group: DEFAULT_GROUP
    alibaba:
      seata:
        tx-service-group:  my_test_tx_group
        service:
          vgroupMapping:
            # 事务群组,其值为seata server端配置的seata集群名,与registry.nacos.cluster保持一致,默认是default
             my_test_tx_group: default 

4.对应的分布式事务方法加注解 @GlobalTransactional(rollbackFor = Exception.class)

5.启动类

 

您好!关于 Seata 集群的搭建和应用,我可以给您一些基本的指导。 首先,Seata 是一款开源的分布式事务解决方案,它可以帮助应用在分布式环境下维护数据一致性。下面是大致的 Seata 集群搭建和应用的步骤: 1. 下载和安装 Seata:您可以从 Seata 的官方网站下载最新的 Seata 版本,并按照官方文档进行安装。 2. 配置 Seata 服务端:在配置文件中,您需要指定 Seata 服务端的相关参数,比如注册中心的地址、数据库存储方式等。 3. 启动 Seata 服务端:根据官方文档,启动 Seata 服务端程序。 4. 配置应用程序:在您的应用程序中,需要添加 Seata 的相关依赖,并配置 Seata 的代理数据源,以便 Seata 可以截获并管理分布式事务。 5. 使用 Seata 进行分布式事务管理:在应用程序中,可以使用 Seata 提供的注解或 API 进行分布式事务的管理。比如 `@GlobalTransactional` 注解可以标记一个方法为全局事务的入口,Seata 会在该方法执行过程中对分布式事务进行管理。 6. 验证和测试:在集群环境下,通过模拟不同分支的事务操作,测试 Seata 是否能够正确地进行分布式事务管理和数据一致性的维护。 请注意,以上只是一个大致的步骤概述,具体的操作和配置还需要根据您的实际情况来进行调整。同时,Seata 的官方文档提供了详细的安装和使用指南,您可以参考官方文档以获得更多细节和帮助。 希望能对您有所帮助!如果还有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值