mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Merge remote-tracking branch 'upstream/finchley' into finchley
This commit is contained in:
commit
2ae97ecb4f
@ -1,5 +0,0 @@
|
|||||||
|
|
||||||
coverage:
|
|
||||||
status:
|
|
||||||
project: off
|
|
||||||
patch: off
|
|
@ -52,7 +52,7 @@ public class DatabaseConfiguration {
|
|||||||
String password = environment.getProperty("mysql.user.password");
|
String password = environment.getProperty("mysql.user.password");
|
||||||
|
|
||||||
DruidDataSource druidDataSource = new DruidDataSource();
|
DruidDataSource druidDataSource = new DruidDataSource();
|
||||||
druidDataSource.setUrl("jdbc:mysql://" + ip + ":" + port + "/" + dbName);
|
druidDataSource.setUrl("jdbc:mysql://" + ip + ":" + port + "/" + dbName + "?serverTimezone=UTC");
|
||||||
druidDataSource.setUsername(userName);
|
druidDataSource.setUsername(userName);
|
||||||
druidDataSource.setPassword(password);
|
druidDataSource.setPassword(password);
|
||||||
druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
|
druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
|
||||||
|
@ -51,7 +51,8 @@ public class DatabaseConfiguration {
|
|||||||
String password = env.getProperty("mysql.user.password");
|
String password = env.getProperty("mysql.user.password");
|
||||||
|
|
||||||
DruidDataSource druidDataSource = new DruidDataSource();
|
DruidDataSource druidDataSource = new DruidDataSource();
|
||||||
druidDataSource.setUrl("jdbc:mysql://" + ip + ":" + port + "/" + dbName);
|
druidDataSource.setUrl(
|
||||||
|
"jdbc:mysql://" + ip + ":" + port + "/" + dbName + "?serverTimezone=UTC");
|
||||||
druidDataSource.setUsername(userName);
|
druidDataSource.setUsername(userName);
|
||||||
druidDataSource.setPassword(password);
|
druidDataSource.setPassword(password);
|
||||||
druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
|
druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
|
||||||
|
@ -46,86 +46,86 @@ import java.util.Random;
|
|||||||
@RestController
|
@RestController
|
||||||
public class OrderController {
|
public class OrderController {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);
|
||||||
private static final String SUCCESS = "SUCCESS";
|
private static final String SUCCESS = "SUCCESS";
|
||||||
private static final String FAIL = "FAIL";
|
private static final String FAIL = "FAIL";
|
||||||
private static final String USER_ID = "U100001";
|
private static final String USER_ID = "U100001";
|
||||||
private static final String COMMODITY_CODE = "C00321";
|
private static final String COMMODITY_CODE = "C00321";
|
||||||
|
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
private final RestTemplate restTemplate;
|
private final RestTemplate restTemplate;
|
||||||
private Random random;
|
private Random random;
|
||||||
|
|
||||||
public OrderController(JdbcTemplate jdbcTemplate, RestTemplate restTemplate) {
|
public OrderController(JdbcTemplate jdbcTemplate, RestTemplate restTemplate) {
|
||||||
this.jdbcTemplate = jdbcTemplate;
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
this.restTemplate = restTemplate;
|
this.restTemplate = restTemplate;
|
||||||
this.random = new Random();
|
this.random = new Random();
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/order", method = RequestMethod.POST, produces = "application/json")
|
@RequestMapping(value = "/order", method = RequestMethod.POST, produces = "application/json")
|
||||||
public String order(String userId, String commodityCode, int orderCount) {
|
public String order(String userId, String commodityCode, int orderCount) {
|
||||||
LOGGER.info("Order Service Begin ... xid: " + RootContext.getXID());
|
LOGGER.info("Order Service Begin ... xid: " + RootContext.getXID());
|
||||||
|
|
||||||
int orderMoney = calculate(commodityCode, orderCount);
|
int orderMoney = calculate(commodityCode, orderCount);
|
||||||
|
|
||||||
invokerAccountService(orderMoney);
|
invokerAccountService(orderMoney);
|
||||||
|
|
||||||
final Order order = new Order();
|
final Order order = new Order();
|
||||||
order.userId = userId;
|
order.userId = userId;
|
||||||
order.commodityCode = commodityCode;
|
order.commodityCode = commodityCode;
|
||||||
order.count = orderCount;
|
order.count = orderCount;
|
||||||
order.money = orderMoney;
|
order.money = orderMoney;
|
||||||
|
|
||||||
KeyHolder keyHolder = new GeneratedKeyHolder();
|
KeyHolder keyHolder = new GeneratedKeyHolder();
|
||||||
|
|
||||||
int result = jdbcTemplate.update(new PreparedStatementCreator() {
|
int result = jdbcTemplate.update(new PreparedStatementCreator() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreparedStatement createPreparedStatement(Connection con)
|
public PreparedStatement createPreparedStatement(Connection con)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
PreparedStatement pst = con.prepareStatement(
|
PreparedStatement pst = con.prepareStatement(
|
||||||
"insert into order_tbl (user_id, commodity_code, count, money) values (?, ?, ?, ?)",
|
"insert into order_tbl (user_id, commodity_code, count, money) values (?, ?, ?, ?)",
|
||||||
PreparedStatement.RETURN_GENERATED_KEYS);
|
PreparedStatement.RETURN_GENERATED_KEYS);
|
||||||
pst.setObject(1, order.userId);
|
pst.setObject(1, order.userId);
|
||||||
pst.setObject(2, order.commodityCode);
|
pst.setObject(2, order.commodityCode);
|
||||||
pst.setObject(3, order.count);
|
pst.setObject(3, order.count);
|
||||||
pst.setObject(4, order.money);
|
pst.setObject(4, order.money);
|
||||||
return pst;
|
return pst;
|
||||||
}
|
}
|
||||||
}, keyHolder);
|
}, keyHolder);
|
||||||
|
|
||||||
order.id = keyHolder.getKey().longValue();
|
order.id = keyHolder.getKey().longValue();
|
||||||
|
|
||||||
// if (random.nextBoolean()) {
|
if (random.nextBoolean()) {
|
||||||
// throw new RuntimeException("this is a mock Exception");
|
throw new RuntimeException("this is a mock Exception");
|
||||||
// }
|
}
|
||||||
|
|
||||||
LOGGER.info("Order Service End ... Created " + order);
|
LOGGER.info("Order Service End ... Created " + order);
|
||||||
|
|
||||||
if (result == 1) {
|
if (result == 1) {
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int calculate(String commodityId, int orderCount) {
|
private int calculate(String commodityId, int orderCount) {
|
||||||
return 2 * orderCount;
|
return 2 * orderCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void invokerAccountService(int orderMoney) {
|
private void invokerAccountService(int orderMoney) {
|
||||||
String url = "http://127.0.0.1:18084/account";
|
String url = "http://127.0.0.1:18084/account";
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
|
|
||||||
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
|
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
|
||||||
|
|
||||||
map.add("userId", USER_ID);
|
map.add("userId", USER_ID);
|
||||||
map.add("money", orderMoney + "");
|
map.add("money", orderMoney + "");
|
||||||
|
|
||||||
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(
|
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(
|
||||||
map, headers);
|
map, headers);
|
||||||
|
|
||||||
ResponseEntity<String> response = restTemplate.postForEntity(url, request,
|
ResponseEntity<String> response = restTemplate.postForEntity(url, request,
|
||||||
String.class);
|
String.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ public class DatabaseConfiguration {
|
|||||||
String password = environment.getProperty("mysql.user.password");
|
String password = environment.getProperty("mysql.user.password");
|
||||||
|
|
||||||
DruidDataSource druidDataSource = new DruidDataSource();
|
DruidDataSource druidDataSource = new DruidDataSource();
|
||||||
druidDataSource.setUrl("jdbc:mysql://" + ip + ":" + port + "/" + dbName);
|
druidDataSource.setUrl("jdbc:mysql://" + ip + ":" + port + "/" + dbName + "?serverTimezone=UTC");
|
||||||
druidDataSource.setUsername(userName);
|
druidDataSource.setUsername(userName);
|
||||||
druidDataSource.setPassword(password);
|
druidDataSource.setPassword(password);
|
||||||
druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
|
druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
|
||||||
|
@ -29,12 +29,12 @@ public class ConsumerApplication {
|
|||||||
return new RestTemplate();
|
return new RestTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@LoadBalanced
|
@LoadBalanced
|
||||||
@Bean
|
@Bean
|
||||||
@SentinelRestTemplate
|
@SentinelRestTemplate
|
||||||
public RestTemplate restTemplate1() {
|
public RestTemplate restTemplate1() {
|
||||||
return new RestTemplate();
|
return new RestTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(ConsumerApplication.class, args);
|
SpringApplication.run(ConsumerApplication.class, args);
|
||||||
|
@ -21,12 +21,8 @@ import com.alibaba.nacos.api.config.ConfigService;
|
|||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
@ -36,6 +32,7 @@ import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME;
|
|||||||
import static com.alibaba.nacos.api.PropertyKeyConst.CONTEXT_PATH;
|
import static com.alibaba.nacos.api.PropertyKeyConst.CONTEXT_PATH;
|
||||||
import static com.alibaba.nacos.api.PropertyKeyConst.ENCODE;
|
import static com.alibaba.nacos.api.PropertyKeyConst.ENCODE;
|
||||||
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
|
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
|
||||||
|
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT_PORT;
|
||||||
import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
|
import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
|
||||||
import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY;
|
import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY;
|
||||||
import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
|
import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
|
||||||
@ -331,7 +328,17 @@ public class NacosConfigProperties {
|
|||||||
properties.put(SECRET_KEY, Objects.toString(this.secretKey, ""));
|
properties.put(SECRET_KEY, Objects.toString(this.secretKey, ""));
|
||||||
properties.put(CONTEXT_PATH, Objects.toString(this.contextPath, ""));
|
properties.put(CONTEXT_PATH, Objects.toString(this.contextPath, ""));
|
||||||
properties.put(CLUSTER_NAME, Objects.toString(this.clusterName, ""));
|
properties.put(CLUSTER_NAME, Objects.toString(this.clusterName, ""));
|
||||||
properties.put(ENDPOINT, Objects.toString(this.endpoint, ""));
|
|
||||||
|
String endpoint = Objects.toString(this.endpoint, "");
|
||||||
|
if (endpoint.contains(":")) {
|
||||||
|
int index = endpoint.indexOf(":");
|
||||||
|
properties.put(ENDPOINT, endpoint.substring(0, index));
|
||||||
|
properties.put(ENDPOINT_PORT, endpoint.substring(index + 1));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
properties.put(ENDPOINT, endpoint);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
configService = NacosFactory.createConfigService(properties);
|
configService = NacosFactory.createConfigService(properties);
|
||||||
return configService;
|
return configService;
|
||||||
|
@ -391,7 +391,16 @@ public class NacosDiscoveryProperties {
|
|||||||
properties.put(SERVER_ADDR, serverAddr);
|
properties.put(SERVER_ADDR, serverAddr);
|
||||||
properties.put(NAMESPACE, namespace);
|
properties.put(NAMESPACE, namespace);
|
||||||
properties.put(UtilAndComs.NACOS_NAMING_LOG_NAME, logName);
|
properties.put(UtilAndComs.NACOS_NAMING_LOG_NAME, logName);
|
||||||
properties.put(ENDPOINT, endpoint);
|
|
||||||
|
if (endpoint.contains(":")) {
|
||||||
|
int index = endpoint.indexOf(":");
|
||||||
|
properties.put(ENDPOINT, endpoint.substring(0, index));
|
||||||
|
properties.put(ENDPOINT_PORT, endpoint.substring(index + 1));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
properties.put(ENDPOINT, endpoint);
|
||||||
|
}
|
||||||
|
|
||||||
properties.put(ACCESS_KEY, accessKey);
|
properties.put(ACCESS_KEY, accessKey);
|
||||||
properties.put(SECRET_KEY, secretKey);
|
properties.put(SECRET_KEY, secretKey);
|
||||||
properties.put(CLUSTER_NAME, clusterName);
|
properties.put(CLUSTER_NAME, clusterName);
|
||||||
|
@ -18,6 +18,7 @@ package org.springframework.cloud.alibaba.nacos.discovery;
|
|||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.cloud.alibaba.nacos.ConditionalOnNacosDiscoveryEnabled;
|
import org.springframework.cloud.alibaba.nacos.ConditionalOnNacosDiscoveryEnabled;
|
||||||
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
|
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
|
||||||
@ -45,6 +46,7 @@ public class NacosDiscoveryClientAutoConfiguration {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
|
@ConditionalOnProperty(value = "spring.cloud.nacos.discovery.watch.enabled", matchIfMissing = true)
|
||||||
public NacosWatch nacosWatch(NacosDiscoveryProperties nacosDiscoveryProperties) {
|
public NacosWatch nacosWatch(NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||||
return new NacosWatch(nacosDiscoveryProperties);
|
return new NacosWatch(nacosDiscoveryProperties);
|
||||||
}
|
}
|
||||||
|
@ -16,5 +16,11 @@
|
|||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
"defaultValue": "false",
|
"defaultValue": "false",
|
||||||
"description": "naming load from local cache at application start ."
|
"description": "naming load from local cache at application start ."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "spring.cloud.nacos.discovery.watch.enabled",
|
||||||
|
"type": "java.lang.Boolean",
|
||||||
|
"defaultValue": "true",
|
||||||
|
"description": "enable nacos discovery watch or not ."
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
|
@ -18,7 +18,6 @@ package org.springframework.cloud.alicloud.acm.bootstrap;
|
|||||||
|
|
||||||
import com.alibaba.edas.acm.ConfigService;
|
import com.alibaba.edas.acm.ConfigService;
|
||||||
import com.alibaba.edas.acm.exception.ConfigException;
|
import com.alibaba.edas.acm.exception.ConfigException;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
|
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package org.springframework.cloud.alicloud.acm.endpoint;
|
package org.springframework.cloud.alicloud.acm.endpoint;
|
||||||
|
|
||||||
import com.alibaba.edas.acm.ConfigService;
|
import com.alibaba.edas.acm.ConfigService;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
||||||
import org.springframework.boot.actuate.health.Health;
|
import org.springframework.boot.actuate.health.Health;
|
||||||
import org.springframework.cloud.alicloud.acm.AcmPropertySourceRepository;
|
import org.springframework.cloud.alicloud.acm.AcmPropertySourceRepository;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user