mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
adapter: use seata-spring-boot-starter's autoConfiguration instead of spring-cloud-alibaba-seata-starter's autoConfiguration
Signed-off-by: slievrly <slievrly@163.com>
This commit is contained in:
parent
54d97a37b4
commit
34d8267068
@ -20,7 +20,7 @@
|
||||
<properties>
|
||||
<sentinel.version>1.6.3</sentinel.version>
|
||||
<oss.version>3.1.0</oss.version>
|
||||
<seata.version>0.9.0</seata.version>
|
||||
<seata.version>1.0.0</seata.version>
|
||||
<nacos.client.version>1.1.4</nacos.client.version>
|
||||
<nacos.config.version>0.8.0</nacos.config.version>
|
||||
<acm.version>1.0.9</acm.version>
|
||||
@ -204,7 +204,7 @@
|
||||
<!--Alibaba Seata-->
|
||||
<dependency>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-all</artifactId>
|
||||
<artifactId>seata-spring-boot-starter</artifactId>
|
||||
<version>${seata.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
@ -29,9 +29,20 @@
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.1.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.31</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -16,15 +16,14 @@
|
||||
|
||||
package com.alibaba.cloud.examples;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import io.seata.rm.datasource.DataSourceProxy;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
/**
|
||||
@ -33,59 +32,19 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@Configuration
|
||||
public class DatabaseConfiguration {
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
public DatabaseConfiguration(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Bean(initMethod = "init", destroyMethod = "close")
|
||||
public DruidDataSource storageDataSource() throws SQLException {
|
||||
|
||||
Environment environment = applicationContext.getEnvironment();
|
||||
|
||||
String ip = environment.getProperty("mysql.server.ip");
|
||||
String port = environment.getProperty("mysql.server.port");
|
||||
String dbName = environment.getProperty("mysql.db.name");
|
||||
|
||||
String userName = environment.getProperty("mysql.user.name");
|
||||
String password = environment.getProperty("mysql.user.password");
|
||||
|
||||
DruidDataSource druidDataSource = new DruidDataSource();
|
||||
druidDataSource.setUrl(
|
||||
"jdbc:mysql://" + ip + ":" + port + "/" + dbName + "?serverTimezone=UTC");
|
||||
druidDataSource.setUsername(userName);
|
||||
druidDataSource.setPassword(password);
|
||||
druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
|
||||
druidDataSource.setInitialSize(0);
|
||||
druidDataSource.setMaxActive(180);
|
||||
druidDataSource.setMaxWait(60000);
|
||||
druidDataSource.setMinIdle(0);
|
||||
druidDataSource.setValidationQuery("Select 'x' from DUAL");
|
||||
druidDataSource.setTestOnBorrow(false);
|
||||
druidDataSource.setTestOnReturn(false);
|
||||
druidDataSource.setTestWhileIdle(true);
|
||||
druidDataSource.setTimeBetweenEvictionRunsMillis(60000);
|
||||
druidDataSource.setMinEvictableIdleTimeMillis(25200000);
|
||||
druidDataSource.setRemoveAbandoned(true);
|
||||
druidDataSource.setRemoveAbandonedTimeout(1800);
|
||||
druidDataSource.setLogAbandoned(true);
|
||||
druidDataSource.setFilters("mergeStat");
|
||||
return druidDataSource;
|
||||
@Bean
|
||||
@Primary
|
||||
@ConfigurationProperties("spring.datasource")
|
||||
public DataSource storageDataSource() {
|
||||
return new DruidDataSource();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSourceProxy dataSourceProxy(DruidDataSource druidDataSource) {
|
||||
return new DataSourceProxy(druidDataSource);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JdbcTemplate jdbcTemplate(DataSourceProxy dataSourceProxy) {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSourceProxy);
|
||||
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
|
||||
jdbcTemplate.update("delete from account_tbl where user_id = 'U100001'");
|
||||
jdbcTemplate.update(
|
||||
"insert into account_tbl(user_id, money) values ('U100001', 10000)");
|
||||
jdbcTemplate.update("insert into account_tbl(user_id, money) values ('U100001', 10000)");
|
||||
|
||||
return jdbcTemplate;
|
||||
}
|
||||
|
@ -1,9 +1,28 @@
|
||||
spring.application.name=account-service
|
||||
server.port=18084
|
||||
|
||||
mysql.server.ip=127.0.0.1
|
||||
mysql.server.port=3306
|
||||
mysql.db.name=demo
|
||||
spring.datasource.name="accountDataSource"
|
||||
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
|
||||
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
|
||||
spring.datasource.url=jdbc:mysql://rm-2zetd9474ydd1g5955o.mysql.rds.aliyuncs.com:3306/fescar?useSSL=false&serverTimezone=UTC
|
||||
spring.datasource.username=workshop
|
||||
spring.datasource.password=Workshop123
|
||||
spring.datasource.druid.max-active=20
|
||||
spring.datasource.druid.min-idle=2
|
||||
spring.datasource.druid.initial-size=2
|
||||
|
||||
seata.enabled=true
|
||||
seata.service.vgroup-mapping=default
|
||||
seata.service.grouplist=127.0.0.1:8091
|
||||
seata.service.disable-global-transaction=false
|
||||
|
||||
## if use registry center
|
||||
#seata.registry.type=nacos
|
||||
#seata.registry.nacos.cluster=default
|
||||
#seata.registry.nacos.server-addr=localhost
|
||||
#
|
||||
## if use config center
|
||||
#seata.config.type=apollo
|
||||
#seata.config.apollo.apollo-meta=http://192.168.1.204:8801
|
||||
#seata.config.apollo.app-id=seata-server
|
||||
|
||||
mysql.user.name=root
|
||||
mysql.user.password=123456
|
||||
|
@ -1,67 +0,0 @@
|
||||
transport {
|
||||
# tcp udt unix-domain-socket
|
||||
type = "TCP"
|
||||
#NIO NATIVE
|
||||
server = "NIO"
|
||||
#enable heartbeat
|
||||
heartbeat = false
|
||||
#thread factory for netty
|
||||
thread-factory {
|
||||
boss-thread-prefix = "NettyBoss"
|
||||
worker-thread-prefix = "NettyServerNIOWorker"
|
||||
server-executor-thread-prefix = "NettyServerBizHandler"
|
||||
share-boss-worker = false
|
||||
client-selector-thread-prefix = "NettyClientSelector"
|
||||
client-selector-thread-size = 1
|
||||
client-worker-thread-prefix = "NettyClientWorkerThread"
|
||||
# netty boss thread size,will not be used for UDT
|
||||
boss-thread-size = 1
|
||||
#auto default pin or 8
|
||||
worker-thread-size = 8
|
||||
}
|
||||
shutdown {
|
||||
# when destroy server, wait seconds
|
||||
wait = 3
|
||||
}
|
||||
serialization = "seata"
|
||||
compressor = "none"
|
||||
}
|
||||
service {
|
||||
#vgroup->rgroup
|
||||
vgroup_mapping.account-service-seata-service-group = "default"
|
||||
#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"
|
||||
}
|
||||
client {
|
||||
async.commit.buffer.limit = 10000
|
||||
lock {
|
||||
retry.internal = 10
|
||||
retry.times = 30
|
||||
}
|
||||
report.retry.count = 5
|
||||
tm.commit.retry.count = 1
|
||||
tm.rollback.retry.count = 1
|
||||
}
|
||||
transaction {
|
||||
undo.data.validation = true
|
||||
undo.log.serialization = "jackson"
|
||||
undo.log.save.days = 7
|
||||
#schedule delete expired undo_log in milliseconds
|
||||
undo.log.delete.period = 86400000
|
||||
undo.log.table = "undo_log"
|
||||
}
|
||||
|
||||
support {
|
||||
## spring
|
||||
spring {
|
||||
# auto proxy the DataSource bean
|
||||
datasource.autoproxy = false
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
registry {
|
||||
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
|
||||
type = "file"
|
||||
|
||||
nacos {
|
||||
serverAddr = "localhost"
|
||||
namespace = ""
|
||||
cluster = "default"
|
||||
}
|
||||
eureka {
|
||||
serviceUrl = "http://localhost:8761/eureka"
|
||||
application = "default"
|
||||
weight = "1"
|
||||
}
|
||||
redis {
|
||||
serverAddr = "localhost:6379"
|
||||
db = "0"
|
||||
}
|
||||
zk {
|
||||
cluster = "default"
|
||||
serverAddr = "127.0.0.1:2181"
|
||||
session.timeout = 6000
|
||||
connect.timeout = 2000
|
||||
}
|
||||
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 = "localhost"
|
||||
namespace = ""
|
||||
}
|
||||
consul {
|
||||
serverAddr = "127.0.0.1:8500"
|
||||
}
|
||||
apollo {
|
||||
app.id = "seata-server"
|
||||
apollo.meta = "http://192.168.1.204:8801"
|
||||
}
|
||||
zk {
|
||||
serverAddr = "127.0.0.1:2181"
|
||||
session.timeout = 6000
|
||||
connect.timeout = 2000
|
||||
}
|
||||
etcd3 {
|
||||
serverAddr = "http://localhost:2379"
|
||||
}
|
||||
file {
|
||||
name = "file.conf"
|
||||
}
|
||||
}
|
@ -20,6 +20,10 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
|
||||
|
@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
@ -87,11 +88,13 @@ public class HomeController {
|
||||
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(
|
||||
map, headers);
|
||||
|
||||
ResponseEntity<String> response = restTemplate.postForEntity(url, request,
|
||||
String.class);
|
||||
|
||||
ResponseEntity<String> response;
|
||||
try {
|
||||
response = restTemplate.postForEntity(url, request, String.class);
|
||||
} catch (Exception exx) {
|
||||
return "mock error";
|
||||
}
|
||||
result = response.getBody();
|
||||
|
||||
if (!SUCCESS.equals(result)) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
@ -6,3 +6,18 @@ spring.application.name=business-service
|
||||
#feign.sentinel.enabled=true
|
||||
|
||||
logging.level.io.seata=debug
|
||||
|
||||
seata.enabled=true
|
||||
seata.service.vgroup-mapping=default
|
||||
seata.service.grouplist=127.0.0.1:8091
|
||||
seata.service.disable-global-transaction=false
|
||||
|
||||
## if use registry center
|
||||
#seata.registry.type=nacos
|
||||
#seata.registry.nacos.cluster=default
|
||||
#seata.registry.nacos.server-addr=localhost
|
||||
#
|
||||
## if use config center
|
||||
#seata.config.type=apollo
|
||||
#seata.config.apollo.apollo-meta=http://192.168.1.204:8801
|
||||
#seata.config.apollo.app-id=seata-server
|
@ -1,67 +1,4 @@
|
||||
transport {
|
||||
# tcp udt unix-domain-socket
|
||||
type = "TCP"
|
||||
#NIO NATIVE
|
||||
server = "NIO"
|
||||
#enable heartbeat
|
||||
heartbeat = false
|
||||
#thread factory for netty
|
||||
thread-factory {
|
||||
boss-thread-prefix = "NettyBoss"
|
||||
worker-thread-prefix = "NettyServerNIOWorker"
|
||||
server-executor-thread-prefix = "NettyServerBizHandler"
|
||||
share-boss-worker = false
|
||||
client-selector-thread-prefix = "NettyClientSelector"
|
||||
client-selector-thread-size = 1
|
||||
client-worker-thread-prefix = "NettyClientWorkerThread"
|
||||
# netty boss thread size,will not be used for UDT
|
||||
boss-thread-size = 1
|
||||
#auto default pin or 8
|
||||
worker-thread-size = 8
|
||||
}
|
||||
shutdown {
|
||||
# when destroy server, wait seconds
|
||||
wait = 3
|
||||
}
|
||||
serialization = "seata"
|
||||
compressor = "none"
|
||||
}
|
||||
service {
|
||||
#vgroup->rgroup
|
||||
vgroup_mapping.business-service-seata-service-group = "default"
|
||||
#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"
|
||||
}
|
||||
client {
|
||||
async.commit.buffer.limit = 10000
|
||||
lock {
|
||||
retry.internal = 10
|
||||
retry.times = 30
|
||||
}
|
||||
report.retry.count = 5
|
||||
tm.commit.retry.count = 1
|
||||
tm.rollback.retry.count = 1
|
||||
}
|
||||
transaction {
|
||||
undo.data.validation = true
|
||||
undo.log.serialization = "jackson"
|
||||
undo.log.save.days = 7
|
||||
#schedule delete expired undo_log in milliseconds
|
||||
undo.log.delete.period = 86400000
|
||||
undo.log.table = "undo_log"
|
||||
}
|
||||
|
||||
support {
|
||||
## spring
|
||||
spring {
|
||||
# auto proxy the DataSource bean
|
||||
datasource.autoproxy = false
|
||||
}
|
||||
disableGlobalTransaction = false
|
||||
}
|
@ -29,9 +29,20 @@
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.1.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.31</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -16,15 +16,14 @@
|
||||
|
||||
package com.alibaba.cloud.examples;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import io.seata.rm.datasource.DataSourceProxy;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
/**
|
||||
@ -33,55 +32,16 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@Configuration
|
||||
public class DatabaseConfiguration {
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
public DatabaseConfiguration(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Bean(initMethod = "init", destroyMethod = "close")
|
||||
public DruidDataSource storageDataSource() throws SQLException {
|
||||
|
||||
Environment env = applicationContext.getEnvironment();
|
||||
|
||||
String ip = env.getProperty("mysql.server.ip");
|
||||
String port = env.getProperty("mysql.server.port");
|
||||
String dbName = env.getProperty("mysql.db.name");
|
||||
|
||||
String userName = env.getProperty("mysql.user.name");
|
||||
String password = env.getProperty("mysql.user.password");
|
||||
|
||||
DruidDataSource druidDataSource = new DruidDataSource();
|
||||
druidDataSource.setUrl(
|
||||
"jdbc:mysql://" + ip + ":" + port + "/" + dbName + "?serverTimezone=UTC");
|
||||
druidDataSource.setUsername(userName);
|
||||
druidDataSource.setPassword(password);
|
||||
druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
|
||||
druidDataSource.setInitialSize(0);
|
||||
druidDataSource.setMaxActive(180);
|
||||
druidDataSource.setMaxWait(60000);
|
||||
druidDataSource.setMinIdle(0);
|
||||
druidDataSource.setValidationQuery("Select 'x' from DUAL");
|
||||
druidDataSource.setTestOnBorrow(false);
|
||||
druidDataSource.setTestOnReturn(false);
|
||||
druidDataSource.setTestWhileIdle(true);
|
||||
druidDataSource.setTimeBetweenEvictionRunsMillis(60000);
|
||||
druidDataSource.setMinEvictableIdleTimeMillis(25200000);
|
||||
druidDataSource.setRemoveAbandoned(true);
|
||||
druidDataSource.setRemoveAbandonedTimeout(1800);
|
||||
druidDataSource.setLogAbandoned(true);
|
||||
druidDataSource.setFilters("mergeStat");
|
||||
return druidDataSource;
|
||||
@Bean
|
||||
@Primary
|
||||
@ConfigurationProperties("spring.datasource")
|
||||
public DataSource storageDataSource() {
|
||||
return new DruidDataSource();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSourceProxy dataSourceProxy(DruidDataSource druidDataSource) {
|
||||
return new DataSourceProxy(druidDataSource);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JdbcTemplate jdbcTemplate(DataSourceProxy dataSourceProxy) {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSourceProxy);
|
||||
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
|
||||
jdbcTemplate.execute("TRUNCATE TABLE order_tbl");
|
||||
|
||||
|
@ -1,9 +1,27 @@
|
||||
spring.application.name=order-service
|
||||
server.port=18083
|
||||
|
||||
mysql.server.ip=127.0.0.1
|
||||
mysql.server.port=3306
|
||||
mysql.db.name=demo
|
||||
spring.datasource.name="orderDataSource"
|
||||
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
|
||||
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
|
||||
spring.datasource.url=jdbc:mysql://rm-2zetd9474ydd1g5955o.mysql.rds.aliyuncs.com:3306/fescar?useSSL=false&serverTimezone=UTC
|
||||
spring.datasource.username=workshop
|
||||
spring.datasource.password=Workshop123
|
||||
spring.datasource.druid.max-active=20
|
||||
spring.datasource.druid.min-idle=2
|
||||
spring.datasource.druid.initial-size=2
|
||||
|
||||
mysql.user.name=root
|
||||
mysql.user.password=123456
|
||||
seata.enabled=true
|
||||
seata.service.vgroup-mapping=default
|
||||
seata.service.grouplist=127.0.0.1:8091
|
||||
seata.service.disable-global-transaction=false
|
||||
|
||||
## if use registry center
|
||||
#seata.registry.type=nacos
|
||||
#seata.registry.nacos.cluster=default
|
||||
#seata.registry.nacos.server-addr=localhost
|
||||
#
|
||||
## if use config center
|
||||
#seata.config.type=apollo
|
||||
#seata.config.apollo.apollo-meta=http://192.168.1.204:8801
|
||||
#seata.config.apollo.app-id=seata-server
|
||||
|
@ -1,67 +0,0 @@
|
||||
transport {
|
||||
# tcp udt unix-domain-socket
|
||||
type = "TCP"
|
||||
#NIO NATIVE
|
||||
server = "NIO"
|
||||
#enable heartbeat
|
||||
heartbeat = false
|
||||
#thread factory for netty
|
||||
thread-factory {
|
||||
boss-thread-prefix = "NettyBoss"
|
||||
worker-thread-prefix = "NettyServerNIOWorker"
|
||||
server-executor-thread-prefix = "NettyServerBizHandler"
|
||||
share-boss-worker = false
|
||||
client-selector-thread-prefix = "NettyClientSelector"
|
||||
client-selector-thread-size = 1
|
||||
client-worker-thread-prefix = "NettyClientWorkerThread"
|
||||
# netty boss thread size,will not be used for UDT
|
||||
boss-thread-size = 1
|
||||
#auto default pin or 8
|
||||
worker-thread-size = 8
|
||||
}
|
||||
shutdown {
|
||||
# when destroy server, wait seconds
|
||||
wait = 3
|
||||
}
|
||||
serialization = "seata"
|
||||
compressor = "none"
|
||||
}
|
||||
service {
|
||||
#vgroup->rgroup
|
||||
vgroup_mapping.order-service-seata-service-group = "default"
|
||||
#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"
|
||||
}
|
||||
client {
|
||||
async.commit.buffer.limit = 10000
|
||||
lock {
|
||||
retry.internal = 10
|
||||
retry.times = 30
|
||||
}
|
||||
report.retry.count = 5
|
||||
tm.commit.retry.count = 1
|
||||
tm.rollback.retry.count = 1
|
||||
}
|
||||
transaction {
|
||||
undo.data.validation = true
|
||||
undo.log.serialization = "jackson"
|
||||
undo.log.save.days = 7
|
||||
#schedule delete expired undo_log in milliseconds
|
||||
undo.log.delete.period = 86400000
|
||||
undo.log.table = "undo_log"
|
||||
}
|
||||
|
||||
support {
|
||||
## spring
|
||||
spring {
|
||||
# auto proxy the DataSource bean
|
||||
datasource.autoproxy = false
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
registry {
|
||||
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
|
||||
type = "file"
|
||||
|
||||
nacos {
|
||||
serverAddr = "localhost"
|
||||
namespace = ""
|
||||
cluster = "default"
|
||||
}
|
||||
eureka {
|
||||
serviceUrl = "http://localhost:8761/eureka"
|
||||
application = "default"
|
||||
weight = "1"
|
||||
}
|
||||
redis {
|
||||
serverAddr = "localhost:6379"
|
||||
db = "0"
|
||||
}
|
||||
zk {
|
||||
cluster = "default"
|
||||
serverAddr = "127.0.0.1:2181"
|
||||
session.timeout = 6000
|
||||
connect.timeout = 2000
|
||||
}
|
||||
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 = "localhost"
|
||||
namespace = ""
|
||||
}
|
||||
consul {
|
||||
serverAddr = "127.0.0.1:8500"
|
||||
}
|
||||
apollo {
|
||||
app.id = "seata-server"
|
||||
apollo.meta = "http://192.168.1.204:8801"
|
||||
}
|
||||
zk {
|
||||
serverAddr = "127.0.0.1:2181"
|
||||
session.timeout = 6000
|
||||
connect.timeout = 2000
|
||||
}
|
||||
etcd3 {
|
||||
serverAddr = "http://localhost:2379"
|
||||
}
|
||||
file {
|
||||
name = "file.conf"
|
||||
}
|
||||
}
|
@ -24,19 +24,24 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.1.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.1.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.31</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -16,15 +16,14 @@
|
||||
|
||||
package com.alibaba.cloud.examples;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import io.seata.rm.datasource.DataSourceProxy;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
/**
|
||||
@ -33,60 +32,20 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@Configuration
|
||||
public class DatabaseConfiguration {
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
public DatabaseConfiguration(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Bean(initMethod = "init", destroyMethod = "close")
|
||||
public DruidDataSource storageDataSource() throws SQLException {
|
||||
|
||||
Environment environment = applicationContext.getEnvironment();
|
||||
|
||||
String ip = environment.getProperty("mysql.server.ip");
|
||||
String port = environment.getProperty("mysql.server.port");
|
||||
String dbName = environment.getProperty("mysql.db.name");
|
||||
|
||||
String userName = environment.getProperty("mysql.user.name");
|
||||
String password = environment.getProperty("mysql.user.password");
|
||||
|
||||
DruidDataSource druidDataSource = new DruidDataSource();
|
||||
druidDataSource.setUrl(
|
||||
"jdbc:mysql://" + ip + ":" + port + "/" + dbName + "?serverTimezone=UTC");
|
||||
druidDataSource.setUsername(userName);
|
||||
druidDataSource.setPassword(password);
|
||||
druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
|
||||
druidDataSource.setInitialSize(0);
|
||||
druidDataSource.setMaxActive(180);
|
||||
druidDataSource.setMaxWait(60000);
|
||||
druidDataSource.setMinIdle(0);
|
||||
druidDataSource.setValidationQuery("Select 'x' from DUAL");
|
||||
druidDataSource.setTestOnBorrow(false);
|
||||
druidDataSource.setTestOnReturn(false);
|
||||
druidDataSource.setTestWhileIdle(true);
|
||||
druidDataSource.setTimeBetweenEvictionRunsMillis(60000);
|
||||
druidDataSource.setMinEvictableIdleTimeMillis(25200000);
|
||||
druidDataSource.setRemoveAbandoned(true);
|
||||
druidDataSource.setRemoveAbandonedTimeout(1800);
|
||||
druidDataSource.setLogAbandoned(true);
|
||||
druidDataSource.setFilters("mergeStat");
|
||||
return druidDataSource;
|
||||
@Bean
|
||||
@Primary
|
||||
@ConfigurationProperties("spring.datasource")
|
||||
public DataSource storageDataSource() {
|
||||
return new DruidDataSource();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSourceProxy dataSourceProxy(DruidDataSource druidDataSource) {
|
||||
return new DataSourceProxy(druidDataSource);
|
||||
}
|
||||
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
|
||||
|
||||
@Bean
|
||||
public JdbcTemplate jdbcTemplate(DataSourceProxy dataSourceProxy) {
|
||||
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSourceProxy);
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
|
||||
jdbcTemplate.update("delete from storage_tbl where commodity_code = 'C00321'");
|
||||
jdbcTemplate.update(
|
||||
"insert into storage_tbl(commodity_code, count) values ('C00321', 100)");
|
||||
jdbcTemplate.update("insert into storage_tbl(commodity_code, count) values ('C00321', 100)");
|
||||
|
||||
return jdbcTemplate;
|
||||
|
||||
|
@ -1,9 +1,28 @@
|
||||
spring.application.name=storage-service
|
||||
server.port=18082
|
||||
|
||||
mysql.server.ip=127.0.0.1
|
||||
mysql.server.port=3306
|
||||
mysql.db.name=demo
|
||||
spring.datasource.name="storageDataSource"
|
||||
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
|
||||
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
|
||||
spring.datasource.url=jdbc:mysql://rm-2zetd9474ydd1g5955o.mysql.rds.aliyuncs.com:3306/fescar?useSSL=false&serverTimezone=UTC
|
||||
spring.datasource.username=workshop
|
||||
spring.datasource.password=Workshop123
|
||||
spring.datasource.druid.max-active=20
|
||||
spring.datasource.druid.min-idle=2
|
||||
spring.datasource.druid.initial-size=2
|
||||
|
||||
mysql.user.name=root
|
||||
mysql.user.password=123456
|
||||
|
||||
seata.enabled=true
|
||||
seata.service.vgroup-mapping=default
|
||||
seata.service.grouplist=127.0.0.1:8091
|
||||
seata.service.disable-global-transaction=false
|
||||
|
||||
## if use registry center
|
||||
#seata.registry.type=nacos
|
||||
#seata.registry.nacos.cluster=default
|
||||
#seata.registry.nacos.server-addr=localhost
|
||||
#
|
||||
## if use config center
|
||||
#seata.config.type=apollo
|
||||
#seata.config.apollo.apollo-meta=http://192.168.1.204:8801
|
||||
#seata.config.apollo.app-id=seata-server
|
||||
|
@ -1,67 +0,0 @@
|
||||
transport {
|
||||
# tcp udt unix-domain-socket
|
||||
type = "TCP"
|
||||
#NIO NATIVE
|
||||
server = "NIO"
|
||||
#enable heartbeat
|
||||
heartbeat = false
|
||||
#thread factory for netty
|
||||
thread-factory {
|
||||
boss-thread-prefix = "NettyBoss"
|
||||
worker-thread-prefix = "NettyServerNIOWorker"
|
||||
server-executor-thread-prefix = "NettyServerBizHandler"
|
||||
share-boss-worker = false
|
||||
client-selector-thread-prefix = "NettyClientSelector"
|
||||
client-selector-thread-size = 1
|
||||
client-worker-thread-prefix = "NettyClientWorkerThread"
|
||||
# netty boss thread size,will not be used for UDT
|
||||
boss-thread-size = 1
|
||||
#auto default pin or 8
|
||||
worker-thread-size = 8
|
||||
}
|
||||
shutdown {
|
||||
# when destroy server, wait seconds
|
||||
wait = 3
|
||||
}
|
||||
serialization = "seata"
|
||||
compressor = "none"
|
||||
}
|
||||
service {
|
||||
#vgroup->rgroup
|
||||
vgroup_mapping.storage-service-seata-service-group = "default"
|
||||
#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"
|
||||
}
|
||||
client {
|
||||
async.commit.buffer.limit = 10000
|
||||
lock {
|
||||
retry.internal = 10
|
||||
retry.times = 30
|
||||
}
|
||||
report.retry.count = 5
|
||||
tm.commit.retry.count = 1
|
||||
tm.rollback.retry.count = 1
|
||||
}
|
||||
transaction {
|
||||
undo.data.validation = true
|
||||
undo.log.serialization = "jackson"
|
||||
undo.log.save.days = 7
|
||||
#schedule delete expired undo_log in milliseconds
|
||||
undo.log.delete.period = 86400000
|
||||
undo.log.table = "undo_log"
|
||||
}
|
||||
|
||||
support {
|
||||
## spring
|
||||
spring {
|
||||
# auto proxy the DataSource bean
|
||||
datasource.autoproxy = false
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
registry {
|
||||
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
|
||||
type = "file"
|
||||
|
||||
nacos {
|
||||
serverAddr = "localhost"
|
||||
namespace = ""
|
||||
cluster = "default"
|
||||
}
|
||||
eureka {
|
||||
serviceUrl = "http://localhost:8761/eureka"
|
||||
application = "default"
|
||||
weight = "1"
|
||||
}
|
||||
redis {
|
||||
serverAddr = "localhost:6379"
|
||||
db = "0"
|
||||
}
|
||||
zk {
|
||||
cluster = "default"
|
||||
serverAddr = "127.0.0.1:2181"
|
||||
session.timeout = 6000
|
||||
connect.timeout = 2000
|
||||
}
|
||||
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 = "localhost"
|
||||
namespace = ""
|
||||
}
|
||||
consul {
|
||||
serverAddr = "127.0.0.1:8500"
|
||||
}
|
||||
apollo {
|
||||
app.id = "seata-server"
|
||||
apollo.meta = "http://192.168.1.204:8801"
|
||||
}
|
||||
zk {
|
||||
serverAddr = "127.0.0.1:2181"
|
||||
session.timeout = 6000
|
||||
connect.timeout = 2000
|
||||
}
|
||||
etcd3 {
|
||||
serverAddr = "http://localhost:2379"
|
||||
}
|
||||
file {
|
||||
name = "file.conf"
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-all</artifactId>
|
||||
<artifactId>seata-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.seata;
|
||||
|
||||
import io.seata.spring.annotation.GlobalTransactionScanner;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author xiaojing
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(SeataProperties.class)
|
||||
public class GlobalTransactionAutoConfiguration {
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
private final SeataProperties seataProperties;
|
||||
|
||||
public GlobalTransactionAutoConfiguration(ApplicationContext applicationContext,
|
||||
SeataProperties seataProperties) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.seataProperties = seataProperties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GlobalTransactionScanner globalTransactionScanner() {
|
||||
|
||||
String applicationName = applicationContext.getEnvironment()
|
||||
.getProperty("spring.application.name");
|
||||
|
||||
String txServiceGroup = seataProperties.getTxServiceGroup();
|
||||
|
||||
if (StringUtils.isEmpty(txServiceGroup)) {
|
||||
txServiceGroup = applicationName + "-seata-service-group";
|
||||
seataProperties.setTxServiceGroup(txServiceGroup);
|
||||
}
|
||||
|
||||
return new GlobalTransactionScanner(applicationName, txServiceGroup);
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.seata;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* @author xiaojing
|
||||
*/
|
||||
@ConfigurationProperties("spring.cloud.alibaba.seata")
|
||||
public class SeataProperties {
|
||||
|
||||
// todo support config Seata server information
|
||||
|
||||
/**
|
||||
* Seata tx service group.default is ${spring.application.name}-seata-service-group.
|
||||
*/
|
||||
private String txServiceGroup;
|
||||
|
||||
public String getTxServiceGroup() {
|
||||
return txServiceGroup;
|
||||
}
|
||||
|
||||
public void setTxServiceGroup(String txServiceGroup) {
|
||||
this.txServiceGroup = txServiceGroup;
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.alibaba.cloud.seata.rest.SeataRestTemplateAutoConfiguration,\
|
||||
com.alibaba.cloud.seata.web.SeataHandlerInterceptorConfiguration,\
|
||||
com.alibaba.cloud.seata.GlobalTransactionAutoConfiguration,\
|
||||
com.alibaba.cloud.seata.feign.SeataFeignClientAutoConfiguration,\
|
||||
com.alibaba.cloud.seata.feign.hystrix.SeataHystrixAutoConfiguration
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user