1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

Merge code from upstream

This commit is contained in:
ly
2019-07-23 21:34:04 +08:00
parent 5cf28cb7a6
commit af09456b7d
587 changed files with 443 additions and 40842 deletions

View File

@@ -14,7 +14,7 @@
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>alibaba-seata-spring-cloud-starter</artifactId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@@ -17,8 +17,6 @@ package com.alibaba.cloud.examples;
import java.util.Random;
import io.seata.core.context.RootContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -26,6 +24,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import io.seata.core.context.RootContext;
/**
* @author xiaojing
*/

View File

@@ -17,15 +17,16 @@ package com.alibaba.cloud.examples;
import java.sql.SQLException;
import com.alibaba.druid.pool.DruidDataSource;
import io.seata.rm.datasource.DataSourceProxy;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate;
import com.alibaba.druid.pool.DruidDataSource;
import io.seata.rm.datasource.DataSourceProxy;
/**
* @author xiaojing
*/
@@ -51,7 +52,8 @@ public class DatabaseConfiguration {
String password = environment.getProperty("mysql.user.password");
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setUrl("jdbc:mysql://" + ip + ":" + port + "/" + dbName + "?serverTimezone=UTC");
druidDataSource.setUrl(
"jdbc:mysql://" + ip + ":" + port + "/" + dbName + "?serverTimezone=UTC");
druidDataSource.setUsername(userName);
druidDataSource.setPassword(password);
druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");

View File

@@ -14,7 +14,7 @@
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>alibaba-seata-spring-cloud-starter</artifactId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
@@ -34,7 +34,7 @@
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>alibaba-sentinel-spring-cloud-starter</artifactId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
</dependencies>

View File

@@ -16,11 +16,6 @@
package com.alibaba.cloud.examples;
import com.alibaba.cloud.examples.BusinessApplication.OrderService;
import com.alibaba.cloud.examples.BusinessApplication.StorageService;
import io.seata.spring.annotation.GlobalTransactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
@@ -34,6 +29,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.alibaba.cloud.examples.BusinessApplication.OrderService;
import com.alibaba.cloud.examples.BusinessApplication.StorageService;
import io.seata.spring.annotation.GlobalTransactional;
/**
* @author xiaojing
*/
@@ -60,7 +60,7 @@ public class HomeController {
}
@GlobalTransactional(timeoutMills = 300000, name = "spring-cloud-demo-tx")
@RequestMapping(value = "/seata/rest", method = RequestMethod.GET, produces = "application/json")
@RequestMapping(value = "/fescar/rest", method = RequestMethod.GET, produces = "application/json")
public String rest() {
String result = restTemplate.getForObject(
@@ -96,7 +96,7 @@ public class HomeController {
}
@GlobalTransactional(timeoutMills = 300000, name = "spring-cloud-demo-tx")
@RequestMapping(value = "/seata/feign", method = RequestMethod.GET, produces = "application/json")
@RequestMapping(value = "/fescar/feign", method = RequestMethod.GET, produces = "application/json")
public String feign() {
String result = storageService.storage(COMMODITY_CODE, ORDER_COUNT);

View File

@@ -5,4 +5,4 @@ spring.application.name=business-service
#feign.hystrix.enabled=true
#feign.sentinel.enabled=true
logging.level.io.seata=debug
logging.level.com.alibaba.fescar=debug

View File

@@ -14,7 +14,7 @@
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>alibaba-seata-spring-cloud-starter</artifactId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@@ -24,6 +24,7 @@ import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate;
import com.alibaba.druid.pool.DruidDataSource;
import io.seata.rm.datasource.DataSourceProxy;
/**

View File

@@ -16,7 +16,10 @@
package com.alibaba.cloud.examples;
import io.seata.core.context.RootContext;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Random;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -35,10 +38,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Random;
import io.seata.core.context.RootContext;
/**
* @author xiaojing

View File

@@ -120,16 +120,16 @@ sh seata-server.sh 8091 file
启动示例后,通过 HTTP 的 GET 方法访问如下两个 URL可以分别验证在 `business-service` 中 通过 RestTemplate 和 FeignClient 调用其他服务的场景。
```$xslt
http://127.0.0.1:18081/seata/feign
http://127.0.0.1:18081/fescar/feign
http://127.0.0.1:18081/seata/rest
http://127.0.0.1:18081/fescar/rest
```
## 如何验证分布式事务成功?
### Xid 信息是否成功传递
在 `account-server`、`order-service` 和 `storage-service` 三个 服务的 Controller 中,第一个执行的逻辑都是输出 RootContext 中的 Xid 信息,如果看到都输出了正确的 Xid 信息,即每次都发生变化,且同一次调用中所有服务的 Xid 都一致。则表明 Seata 的 Xid 的传递和还原是正常的。
在 `account-server`、`order-service` 和 `storage-service` 三个 服务的 Controller 中,第一个执行的逻辑都是输出 RootContext 中的 Xid 信息,如果看到都输出了正确的 Xid 信息,即每次都发生变化,且同一次调用中所有服务的 Xid 都一致。则表明 Fescar 的 Xid 的传递和还原是正常的。
### 数据库中数据是否一致

View File

@@ -14,7 +14,7 @@
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>alibaba-seata-spring-cloud-starter</artifactId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@@ -18,15 +18,16 @@ package com.alibaba.cloud.examples;
import java.sql.SQLException;
import com.alibaba.druid.pool.DruidDataSource;
import io.seata.rm.datasource.DataSourceProxy;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate;
import com.alibaba.druid.pool.DruidDataSource;
import io.seata.rm.datasource.DataSourceProxy;
/**
* @author xiaojing
*/
@@ -52,7 +53,8 @@ public class DatabaseConfiguration {
String password = environment.getProperty("mysql.user.password");
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setUrl("jdbc:mysql://" + ip + ":" + port + "/" + dbName + "?serverTimezone=UTC");
druidDataSource.setUrl(
"jdbc:mysql://" + ip + ":" + port + "/" + dbName + "?serverTimezone=UTC");
druidDataSource.setUsername(userName);
druidDataSource.setPassword(password);
druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");

View File

@@ -16,8 +16,6 @@
package com.alibaba.cloud.examples;
import io.seata.core.context.RootContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -26,6 +24,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import io.seata.core.context.RootContext;
/**
* @author xiaojing
*/