springcloud-eureka-seata 运行示例

seata version:0.6.1

官方quick-start:https://github.com/seata/seata/wiki/Quick-Start

seata-server下载:https://github.com/seata/seata/releases 选择0.6.1 版本

官方demo地址:https://github.com/seata/seata-samples

启动seata-server 

Usage: sh seata-server.sh(for linux and mac) or cmd seata-server.bat(for windows) [options]
  Options:
    --host, -h
      The host to bind.
      Default: 0.0.0.0
    --port, -p
      The port to listen.
      Default: 8091
    --storeMode, -m
      log store mode : file、db
      Default: file
    --help

e.g.

sh seata-server.sh -p 8091 -h 127.0.0.1 -m file

修改配置文件后再启动

修改conf/registry.conf文件

registry.type = "eureka"  #注册发现中心为eureka

registry.eureka.serviceUrl = "${你自己的eureka地址}"

registry.eureka.application = "${注册到eureka中的应用名称}"

 

以下为修改后的registry.conf文件 其他没用的配置被我删了

registry {
  # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
  type = "eureka"
  eureka {
    serviceUrl = "http://localhost:8761/eureka"
    application = "seata-server"
    weight = "1"
  }
}

config {
  # file、nacos 、apollo、zk、consul、etcd3
  type = "file"
  file {
    name = "file.conf"
  }
}

修改demo中的配置,以springcloud-eureka-seata/storage  module下的配置文件为例,其他的module配置均一样

springcloud-eureka-seata 运行示例

修改registry.conf文件

registry.type = "file"   
config.type = "file"  
registry {
  # file 、nacos 、eureka、redis、zk
  type = "file"

...

  file {
    name = "file.conf"
  }
}

config {
  # file、nacos 、apollo、zk
  type = "file"

...

  file {
    name = "file.conf"
  }
}

修改file.conf文件

service.vgroup_mapping.${spring.cloud.alibaba.seata.tx-service-group} = ${注册到eureka中的应用名称}  #seata-server注册到eureka中的application name ${spring.cloud.alibaba.seata.tx-service-group}这个值在properties文件中

${注册到eureka中的应用名称}.grouplist = "${seata-server-IP}:${seata-server-PORT}"  #seata服务的ip 和 端口

...

service {
  #vgroup->rgroup
  vgroup_mapping.icoolh_tx_group = "seata_server"
  #only support single node
  seata_server.grouplist = "127.0.0.1:8091"
  #degrade current not support
  enableDegrade = false
  #disable
  disable = false
  disableGlobalTransaction = false
}

...

 

application.properties文件

spring.cloud.alibaba.seata.tx-service-group = 定义一个tx-server-group名称 
这个名称就是file.conf中的service.vgroup_mapping.${spring.cloud.alibaba.seata.tx-service-group}
spring.application.name=storage-service
server.port=8081
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/seata?useSSL=false&serverTimezone=UTC
spring.datasource.username=workshop
spring.datasource.password=Workshop123
spring.cloud.alibaba.seata.tx-service-group=icoolh_tx_group
logging.level.org.springframework.cloud.alibaba.seata.web=debug
logging.level.io.seata=debug
eureka.instance.hostname=127.0.0.1
eureka.instance.prefer-ip-address=true
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:8761/eureka/

修改完后,启动就可以看效果了。

我运行的时候有个小坑,调用接口的时候报了一个错误springcloud-eureka-seata 运行示例

 

这个错误是由jar版本不一致导致的,直接在pom文件中指定版本就行了

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>5.1.5.RELEASE</version>
        </dependency>
上一篇:Seata 客户端需要同时启动 TM 和 RM 吗?


下一篇:一、seata自动配置