springcloud整合seata实现分布式事务(二)

描述:

本篇文章继承上一篇文章:主要讲述,对于里面的相关的代码,如何改的问题

 

步骤一:改seata1.4.0里面的配置

改seata-1.4.0\conf\file.conf

## transaction log store, only used in seata-server
store {
  ## store mode: file、db、redis
  mode = "db"                                  -----改成db

  ## 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 = "dbcp"                                                 ---这里,可以是dbcp,可以是durid看你自己配置
    ## mysql/oracle/postgresql/h2/oceanbase etc.
    dbType = "mysql"                                                    
    driverClassName = "com.mysql.cj.jdbc.Driver"        --这里要改,要不会报错,原来的没有cj的
    url = "jdbc:mysql://127.0.0.1:3306/seata-server?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8"    --这里要改,用来连接上一篇文章已经创建好的seata-server数据库
    user = "root"                                                        --改数据库用户名
    password = "a123456"                                        --改数据库密码
    minConn = 5
    maxConn = 100
    globalTable = "global_table"
    branchTable = "branch_table"
    lockTable = "lock_table"
    queryLimit = 100
    maxWait = 5000
  }

  ## redis store property
  redis {
    host = "127.0.0.1"
    port = "6379"
    password = ""
    database = "0"
    minConn = 1
    maxConn = 10
    maxTotal = 100
    queryLimit = 100
  }

}
改:seata-1.4.0\conf\registry.conf

registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "eureka"                                          --改这里,改成eureka
  loadBalance = "RandomLoadBalance"
  loadBalanceVirtualNodes = 10

  nacos {
    application = "seata-server"                      
    serverAddr = "127.0.0.1:8848"
    group = "SEATA_GROUP"
    namespace = ""
    cluster = "default"
    username = ""
    password = ""
  }
  eureka {
    serviceUrl = "http://localhost:8761/eureka"          --改这里,改成服务注册中心的地址名
    application = "seata-server"                     --改这里,改成你自己的客户端自己想要定义的名字
    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"
  }
  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 = "127.0.0.1:8848"
    namespace = ""
    group = "SEATA_GROUP"
    username = ""
    password = ""
  }
  consul {
    serverAddr = "127.0.0.1:8500"
  }
  apollo {
    appId = "seata-server"
    apolloMeta = "http://192.168.1.204:8801"
    namespace = "application"
    apolloAccesskeySecret = ""
  }
  zk {
    serverAddr = "127.0.0.1:2181"
    sessionTimeout = 6000
    connectTimeout = 2000
    username = ""
    password = ""
  }
  etcd3 {
    serverAddr = "http://localhost:2379"
  }
  file {
    name = "file.conf"
  }
}


步骤二:修改从网盘上拉取的代码一些配置

修改account-server,order-server,storage-server的pplication.yml

eureka:
    instance:
        hostname: localhost
        prefer-ip-address: true
    client:
        serviceUrl:
            defaultZone: http://${eureka.instance.hostname}:8761/eureka/
feign:
    hystrix:
        enabled: false
    client:
        config:
            default:
                connectTimeout: 60000
                readTimeout: 60000
logging:
    level:
        io:
            seata: info
mybatis:
    mapperLocations: classpath:mapper/*.xml
    typeAliasesPackage: io.seata.sample.entity
server:
    port: 8180
spring:
    application:
        name: order-server
    cloud:
        alibaba:
            seata:
                tx-service-group: fsp_tx_group
    datasource:
        driver-class-name: com.mysql.cj.jdbc.Driver
        password: a123456                           --改这里,改成你自己的用户名
        url: jdbc:mysql://localhost:3306/order?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8
        username: root                              --改这里,改成你自己的密码

步骤三:依次启动项目

一:启动eureka-server

二:启动seata 1.4.0,windows环境下, cd  seata-1.4.0\bin,启动seata-server.bat就好

三:启动相关客户端:account-server,order-server,storage-server

四:调用接口:

http://localhost:8180/order/create?userId=1&productId=1&count=10&money=100  查看效果

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值