https://github.com/seata/seata/releases/download/v0.9.0/seata-server-0.9.0.tar.gz 复制代码
tar -zxvf seata-server-0.9.0.tar.gz 复制代码
registry { #基于naocs serverAdd配置对应的nacos地址 namespace命名空间 #另外还可以基于file 、eureka、redis、zk、consul、etcd3、sofa等可以做相关配置,这里就不一一操作了 type = "nacos" nacos { serverAddr = "192.168.1.19:8848" namespace = "public" cluster = "default" } } config { type = "nacos" nacos { serverAddr = "192.168.1.19:8848" namespace = "public" cluster = "default" } } 复制代码
service.vgroup_mapping.vendor-system-fescar-service=default #vendor-system-fescar-service配置事务组名,跟应用服务上配置一致,后面会提到 service.vgroup_mapping.vendor-position-fescar-service=default 复制代码
-XX:MaxDirectMemorySize=2048m
sh seata-server.sh -h 47.125.114.58
服务启动成功
<!--seata事务组件--> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-seata</artifactId> </dependency> 复制代码
spring: cloud: alibaba: seata: tx-service-group: vendor-system-fescar-servic 复制代码
@Configuration @Import(DataSourcesProperties.class) public class DataSourceProxyAutoConfiguration { private DataSourcesProperties dataSourcesProperties; public DataSourceProxyAutoConfiguration(DataSourcesProperties dataSourcesProperties) { this.dataSourcesProperties = dataSourcesProperties; } /** * create proxy datasource * @return */ @Primary @Bean(name = "dataSource") public DataSource getDatasource(){ HikariDataSource build = DataSourceBuilder.create().url(dataSourcesProperties.getUrl()) .password(dataSourcesProperties.getPassword()) .username(dataSourcesProperties.getUsername()) .type(dataSourcesProperties.getType()) .driverClassName(dataSourcesProperties.getDriverClassName()).build(); return new DataSourceProxy(build); } } 复制代码
public class FescarRequestInterceptor implements RequestInterceptor { private static final String FESCAR_HEADER_NAME = "Fescar-Xid"; @Override public void apply(RequestTemplate requestTemplate) { String xid = RootContext.getXID(); if(StringUtils.isNoneBlank(xid)){ requestTemplate.header(FESCAR_HEADER_NAME,xid); } } } 复制代码