springboot-nacos-feign 集成 seata 1.0.0

1.下载seata服务 

springboot-nacos-feign 集成 seata 1.0.0_第1张图片

 解压后打开文件夹目录结构如下

springboot-nacos-feign 集成 seata 1.0.0_第2张图片

conf目录结构如下

springboot-nacos-feign 集成 seata 1.0.0_第3张图片

2.将file.conf.example中的内容粘贴到file.conf中,并修改conf中的registry.conf和file.conf参数,具体如下

 (1)修改file.conf

springboot-nacos-feign 集成 seata 1.0.0_第4张图片

这里的值my_test_tx_group可以更改也可默认。

springboot-nacos-feign 集成 seata 1.0.0_第5张图片

建表语句:CREATE TABLE `branch_table` (
  `branch_id` bigint(20) NOT NULL,
  `xid` varchar(128) NOT NULL,
  `transaction_id` bigint(20) DEFAULT NULL,
  `resource_group_id` varchar(32) DEFAULT NULL,
  `resource_id` varchar(256) DEFAULT NULL,
  `lock_key` varchar(128) DEFAULT NULL,
  `branch_type` varchar(8) DEFAULT NULL,
  `status` tinyint(4) DEFAULT NULL,
  `client_id` varchar(64) DEFAULT NULL,
  `application_data` varchar(2000) DEFAULT NULL,
  `gmt_create` datetime DEFAULT NULL,
  `gmt_modified` datetime DEFAULT NULL,
  PRIMARY KEY (`branch_id`),
  KEY `idx_xid` (`xid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

 

CREATE TABLE `global_table` (
  `xid` varchar(128) NOT NULL,
  `transaction_id` bigint(20) DEFAULT NULL,
  `status` tinyint(4) NOT NULL,
  `application_id` varchar(32) DEFAULT NULL,
  `transaction_service_group` varchar(32) DEFAULT NULL,
  `transaction_name` varchar(128) DEFAULT NULL,
  `timeout` int(11) DEFAULT NULL,
  `begin_time` bigint(20) DEFAULT NULL,
  `application_data` varchar(2000) DEFAULT NULL,
  `gmt_create` datetime DEFAULT NULL,
  `gmt_modified` datetime DEFAULT NULL,
  PRIMARY KEY (`xid`),
  KEY `idx_gmt_modified_status` (`gmt_modified`,`status`),
  KEY `idx_transaction_id` (`transaction_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
 

CREATE TABLE `lock_table` (
  `row_key` varchar(128) NOT NULL,
  `xid` varchar(96) DEFAULT NULL,
  `transaction_id` mediumtext,
  `branch_id` mediumtext,
  `resource_id` varchar(256) DEFAULT NULL,
  `table_name` varchar(32) DEFAULT NULL,
  `pk` varchar(36) DEFAULT NULL,
  `gmt_create` datetime DEFAULT NULL,
  `gmt_modified` datetime DEFAULT NULL,
  PRIMARY KEY (`row_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
 

(2)修改registry.conf

springboot-nacos-feign 集成 seata 1.0.0_第6张图片

 

3.启动seata服务

点击bin 目录下启动脚本如下图

springboot-nacos-feign 集成 seata 1.0.0_第7张图片

4.在自己创建的服务中引入的jar包:


    com.alibaba.cloud
    spring-cloud-starter-alibaba-seata
    
        
            seata-all
            io.seata
        
    


    io.seata
    seata-all
    1.0.0

 

需要在resources下复制粘贴seata中conf下的file.conf和registry.cof文件如下图:

springboot-nacos-feign 集成 seata 1.0.0_第8张图片

在properties.yml中的配置如下图

springboot-nacos-feign 集成 seata 1.0.0_第9张图片

5.配置代理数据源

@Configuration
public class DataSourceProxyConfig {

    @Value("${mybatis.mapper-locations}")
    private String mapperLocations;

    @Bean
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource druidDataSource(){
        return new DruidDataSource();
    }

    @Bean
    public DataSourceProxy dataSourceProxy(DataSource dataSource) {
        return new DataSourceProxy(dataSource);
    }

    @Bean
    public SqlSessionFactory sqlSessionFactoryBean(DataSourceProxy dataSourceProxy) throws Exception {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(dataSourceProxy);
        sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver()
                .getResources(mapperLocations));
        sqlSessionFactoryBean.setTransactionFactory(new SpringManagedTransactionFactory());
        return sqlSessionFactoryBean.getObject();
    }

}

你可能感兴趣的:(springboot-nacos-feign 集成 seata 1.0.0)