ShardingSphere4.1 + seata1.2+Nacos + Mybatis+springboot.2.2.8.RELEASE

前言

再进行使用seta前务必先看各个版本的参数差异

http://seata.io/zh-cn/docs/user/configurations.html

git地址

https://gitee.com/ksunwang/nacos-sharding(内附nacos 和seata安装包)

参考官网

https://shardingsphere.apache.org/document/legacy/4.x/document/cn/overview/

注意事项

  • seta-server 版本1.0之前和之后略有不一样使用时需注意配置参数有所修改具体请看http://seata.io/zh-cn/docs/user/configurations.html

  • seta版本和引入依赖版本必须一致否则可能会导致 no available service 'null' found, please make sure registry config correct

  • 使用zookeeper或者eurake注册中心与nacos类似

启动Nacos-Server

  1. 下载 Nacos-Server 最新 release 包并解压
  2. 运行Nacos-Server
startup.cmd -m standalone #winsows
sh startup.sh -m standalone #Linux/Unix/Mac

启动seta-server

  1. 下载 seata-Server 最新 release 包并解压

  2. 修改 registry.conf

    registry {
      # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
      type = "nacos"
    
      nacos {
        application = "seata-server"
        serverAddr = "localhost" #ip 没有端口号
        namespace = "public"
        cluster = "default"
        username = "nacos"
        password = "nacos"
      }
     }
     config {
      # file、nacos 、apollo、zk、consul、etcd3
      type = "nacos"
    
      nacos {
        serverAddr = "localhost"
        namespace = "public"
        group = "testSharding"
        username = "nacos"
        password = "nacos"
      }
      }
    
    1. 修改file.conf

      store {
        ## store mode: file、db
        mode = "file"
      
        ## 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) etc.
          datasource = "druid"
          ## mysql/oracle/postgresql/h2/oceanbase etc.
          dbType = "mysql"
          driverClassName = "com.mysql.jdbc.Driver"
          url = "jdbc:mysql://127.0.0.1:3306/seata"
          user = "mysql"
          password = "mysql"
          minConn = 5
          maxConn = 30
          globalTable = "global_table"
          branchTable = "branch_table"
          lockTable = "lock_table"
          queryLimit = 100
          maxWait = 5000
        }
      }
      

引入依赖

   

<properties>
     <java.version>1.8</java.version>
     <spring-cloud-alibaba.version>2.2.0.RELEASE</spring-cloud-alibaba.version>
</properties>
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.1.3</version>
</dependency>
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
    <version>4.1.0</version>
</dependency>
<!-- 使用BASE事务时,需要引入此模块 -->
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-transaction-base-seata-at</artifactId>
    <version>4.1.0</version>
</dependency>
<dependency>
    <groupId>io.seata</groupId>
    <artifactId>seata-all</artifactId>
    <version>1.1.0</version>
</dependency>
<dependency>
    <groupId>com.alibaba.nacos</groupId>
    <artifactId>nacos-client</artifactId>
    <version>1.2.0</version>
</dependency>
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>

<!-- 使用XA事务时,需要引入此模块 -->
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-transaction-xa-core</artifactId>
    <version>4.1.0</version>
</dependency>

配置bean

@Configuration
@EnableTransactionManagement
public class TransactionConfig {

    @Bean
    public PlatformTransactionManager txManager(final DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }

    @Bean
    public JdbcTemplate jdbcTemplate(final DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
}

配置seata客户端registry.conf

和server端一致

配置seata客户端 file.conf

service {

  vgroupMapping.prex_tx_group = "default" #修改事务组名称为:prex_tx_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"
}

springboot+mybatis+seata+nacos(可参考)

https://blog.csdn.net/belovedwxy/article/details/105761838

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值