Merge remote-tracking branch 'origin/fix-bug-202303' into fix-bug-202303
This commit is contained in:
+1
-2
@@ -6,7 +6,6 @@ import org.springframework.boot.SpringApplication;
|
|||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
@@ -19,7 +18,7 @@ public class JeroGatewayApplication implements CommandLineRunner {
|
|||||||
private DynamicRouteLoader dynamicRouteLoader;
|
private DynamicRouteLoader dynamicRouteLoader;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ConfigurableApplicationContext applicationContext = SpringApplication.run(JeroGatewayApplication.class, args);
|
SpringApplication.run(JeroGatewayApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+7
-4
@@ -3,17 +3,20 @@ package com.jero.config;
|
|||||||
/**
|
/**
|
||||||
* nocos配置方式枚举
|
* nocos配置方式枚举
|
||||||
*/
|
*/
|
||||||
public enum RouterDataType {
|
public class RouterDataType {
|
||||||
|
private RouterDataType(){
|
||||||
|
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 数据库加载路由配置
|
* 数据库加载路由配置
|
||||||
*/
|
*/
|
||||||
database,
|
public static final String DATABASE = "database";
|
||||||
/**
|
/**
|
||||||
* 本地yml加载路由配置
|
* 本地yml加载路由配置
|
||||||
*/
|
*/
|
||||||
yml,
|
public static final String YML = "yml";
|
||||||
/**
|
/**
|
||||||
* nacos加载路由配置
|
* nacos加载路由配置
|
||||||
*/
|
*/
|
||||||
nacos
|
public static final String NACOS = "nacos";
|
||||||
}
|
}
|
||||||
|
|||||||
-3
@@ -27,14 +27,11 @@ public class GlobalAccessTokenFilter implements GlobalFilter, Ordered {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||||
// String url = exchange.getRequest().getURI().getPath();
|
|
||||||
// log.info(" access url : "+ url);
|
|
||||||
|
|
||||||
String scheme = exchange.getRequest().getURI().getScheme();
|
String scheme = exchange.getRequest().getURI().getScheme();
|
||||||
String host = exchange.getRequest().getURI().getHost();
|
String host = exchange.getRequest().getURI().getHost();
|
||||||
int port = exchange.getRequest().getURI().getPort();
|
int port = exchange.getRequest().getURI().getPort();
|
||||||
String basePath = scheme + "://" + host + ":" + port;
|
String basePath = scheme + "://" + host + ":" + port;
|
||||||
// log.info(" base path : "+ basePath);
|
|
||||||
|
|
||||||
// 1. 重写StripPrefix(获取真实的URL)
|
// 1. 重写StripPrefix(获取真实的URL)
|
||||||
addOriginalRequestUrl(exchange, exchange.getRequest().getURI());
|
addOriginalRequestUrl(exchange, exchange.getRequest().getURI());
|
||||||
|
|||||||
+4
-2
@@ -5,14 +5,16 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.servlet.Filter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Administrator
|
* @author Administrator
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class SentinelFilterContextConfig {
|
public class SentinelFilterContextConfig {
|
||||||
@Bean
|
@Bean
|
||||||
public FilterRegistrationBean sentinelFilterRegistration() {
|
public FilterRegistrationBean<Filter> sentinelFilterRegistration() {
|
||||||
FilterRegistrationBean registration = new FilterRegistrationBean();
|
FilterRegistrationBean<Filter> registration = new FilterRegistrationBean<>();
|
||||||
registration.setFilter(new CommonFilter());
|
registration.setFilter(new CommonFilter());
|
||||||
registration.addUrlPatterns("/*");
|
registration.addUrlPatterns("/*");
|
||||||
// 入口资源关闭聚合
|
// 入口资源关闭聚合
|
||||||
|
|||||||
+30
-25
@@ -48,7 +48,7 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
|||||||
|
|
||||||
private ApplicationEventPublisher publisher;
|
private ApplicationEventPublisher publisher;
|
||||||
|
|
||||||
// private InMemoryRouteDefinitionRepository repository;
|
private InMemoryRouteDefinitionRepository repository;
|
||||||
|
|
||||||
private DynamicRouteService dynamicRouteService;
|
private DynamicRouteService dynamicRouteService;
|
||||||
|
|
||||||
@@ -59,14 +59,9 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
|||||||
private static String updateRouteText = "update route : {}";
|
private static String updateRouteText = "update route : {}";
|
||||||
|
|
||||||
|
|
||||||
/*public DynamicRouteLoader(InMemoryRouteDefinitionRepository repository, DynamicRouteService dynamicRouteService, RedisUtil redisUtil) {
|
public DynamicRouteLoader(InMemoryRouteDefinitionRepository repository, DynamicRouteService dynamicRouteService, RedisUtil redisUtil) {
|
||||||
|
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.dynamicRouteService = dynamicRouteService;
|
|
||||||
this.redisUtil = redisUtil;
|
|
||||||
}*/
|
|
||||||
public DynamicRouteLoader(DynamicRouteService dynamicRouteService, RedisUtil redisUtil) {
|
|
||||||
|
|
||||||
this.dynamicRouteService = dynamicRouteService;
|
this.dynamicRouteService = dynamicRouteService;
|
||||||
this.redisUtil = redisUtil;
|
this.redisUtil = redisUtil;
|
||||||
}
|
}
|
||||||
@@ -75,11 +70,11 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
|||||||
public void init() {
|
public void init() {
|
||||||
String dataType = GatewayRoutersConfiguration.DATA_TYPE;
|
String dataType = GatewayRoutersConfiguration.DATA_TYPE;
|
||||||
log.info("初始化路由,dataType:"+ dataType);
|
log.info("初始化路由,dataType:"+ dataType);
|
||||||
if (RouterDataType.nacos.toString().endsWith(dataType)) {
|
if (RouterDataType.NACOS.endsWith(dataType)) {
|
||||||
loadRoutesByNacos();
|
loadRoutesByNacos();
|
||||||
}
|
}
|
||||||
//从数据库加载路由
|
//从数据库加载路由
|
||||||
if (RouterDataType.database.toString().endsWith(dataType)) {
|
if (RouterDataType.DATABASE.endsWith(dataType)) {
|
||||||
loadRoutesByRedis();
|
loadRoutesByRedis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,7 +87,7 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
|||||||
*/
|
*/
|
||||||
public Mono<Void> refresh() {
|
public Mono<Void> refresh() {
|
||||||
String dataType = GatewayRoutersConfiguration.DATA_TYPE;
|
String dataType = GatewayRoutersConfiguration.DATA_TYPE;
|
||||||
if (!RouterDataType.yml.toString().endsWith(dataType)) {
|
if (!RouterDataType.YML.endsWith(dataType)) {
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
return Mono.empty();
|
return Mono.empty();
|
||||||
@@ -111,8 +106,9 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
|||||||
String configInfo = "";
|
String configInfo = "";
|
||||||
if (configService == null) {
|
if (configService == null) {
|
||||||
log.warn("initConfigService fail");
|
log.warn("initConfigService fail");
|
||||||
|
}else {
|
||||||
|
configInfo = configService.getConfig(GatewayRoutersConfiguration.DATA_ID, GatewayRoutersConfiguration.ROUTE_GROUP, GatewayRoutersConfiguration.DEFAULT_TIMEOUT);
|
||||||
}
|
}
|
||||||
else configInfo = configService.getConfig(GatewayRoutersConfiguration.DATA_ID, GatewayRoutersConfiguration.ROUTE_GROUP, GatewayRoutersConfiguration.DEFAULT_TIMEOUT);
|
|
||||||
if (StringUtils.isNotBlank(configInfo)) {
|
if (StringUtils.isNotBlank(configInfo)) {
|
||||||
log.info("获取网关当前配置:\r\n{}", configInfo);
|
log.info("获取网关当前配置:\r\n{}", configInfo);
|
||||||
routes = JSON.parseArray(configInfo, RouteDefinition.class);
|
routes = JSON.parseArray(configInfo, RouteDefinition.class);
|
||||||
@@ -189,17 +185,7 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
|||||||
Object predicates = obj.get("predicates");
|
Object predicates = obj.get("predicates");
|
||||||
if (predicates != null) {
|
if (predicates != null) {
|
||||||
JSONArray list = JSON.parseArray(predicates.toString());
|
JSONArray list = JSON.parseArray(predicates.toString());
|
||||||
List<PredicateDefinition> predicateDefinitionList = new ArrayList<>();
|
List<PredicateDefinition> predicateDefinitionList = getPredicateDefinitions(list);
|
||||||
for (Object map : list) {
|
|
||||||
JSONObject json = (JSONObject) map;
|
|
||||||
PredicateDefinition predicateDefinition = new PredicateDefinition();
|
|
||||||
predicateDefinition.setName(json.getString("name"));
|
|
||||||
JSONArray jsonArray = json.getJSONArray("args");
|
|
||||||
for (int j = 0; j < jsonArray.size(); j++) {
|
|
||||||
predicateDefinition.addArg("_genkey" + j, jsonArray.get(j).toString());
|
|
||||||
}
|
|
||||||
predicateDefinitionList.add(predicateDefinition);
|
|
||||||
}
|
|
||||||
route.setPredicates(predicateDefinitionList);
|
route.setPredicates(predicateDefinitionList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,6 +194,16 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
|||||||
JSONArray list = JSON.parseArray(filters.toString());
|
JSONArray list = JSON.parseArray(filters.toString());
|
||||||
List<FilterDefinition> filterDefinitionList = new ArrayList<>();
|
List<FilterDefinition> filterDefinitionList = new ArrayList<>();
|
||||||
if (ObjectUtil.isNotEmpty(list)) {
|
if (ObjectUtil.isNotEmpty(list)) {
|
||||||
|
addFilterDefinition(list, filterDefinitionList);
|
||||||
|
route.setFilters(filterDefinitionList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ls.add(route);
|
||||||
|
}
|
||||||
|
return ls;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addFilterDefinition(JSONArray list, List<FilterDefinition> filterDefinitionList) {
|
||||||
for (Object map : list) {
|
for (Object map : list) {
|
||||||
JSONObject json = (JSONObject) map;
|
JSONObject json = (JSONObject) map;
|
||||||
JSONArray jsonArray = json.getJSONArray("args");
|
JSONArray jsonArray = json.getJSONArray("args");
|
||||||
@@ -220,12 +216,21 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
|
|||||||
filterDefinition.setName(name);
|
filterDefinition.setName(name);
|
||||||
filterDefinitionList.add(filterDefinition);
|
filterDefinitionList.add(filterDefinition);
|
||||||
}
|
}
|
||||||
route.setFilters(filterDefinitionList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<PredicateDefinition> getPredicateDefinitions(JSONArray list) {
|
||||||
|
List<PredicateDefinition> predicateDefinitionList = new ArrayList<>();
|
||||||
|
for (Object map : list) {
|
||||||
|
JSONObject json = (JSONObject) map;
|
||||||
|
PredicateDefinition predicateDefinition = new PredicateDefinition();
|
||||||
|
predicateDefinition.setName(json.getString("name"));
|
||||||
|
JSONArray jsonArray = json.getJSONArray("args");
|
||||||
|
for (int j = 0; j < jsonArray.size(); j++) {
|
||||||
|
predicateDefinition.addArg("_genkey" + j, jsonArray.get(j).toString());
|
||||||
}
|
}
|
||||||
ls.add(route);
|
predicateDefinitionList.add(predicateDefinition);
|
||||||
}
|
}
|
||||||
return ls;
|
return predicateDefinitionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -3,12 +3,15 @@ package com.jero.modules.cloud.constant;
|
|||||||
/**
|
/**
|
||||||
* 微服务单元测试常量定义
|
* 微服务单元测试常量定义
|
||||||
*/
|
*/
|
||||||
public interface CloudConstant {
|
public class CloudConstant {
|
||||||
|
private CloudConstant(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微服务名【对应模块jero-boot-module-demo】
|
* 微服务名【对应模块jero-boot-module-demo】
|
||||||
*/
|
*/
|
||||||
public static final String SERVER_NAME_JeroDemo = "jero-demo";
|
public static final String SERVER_NAME_JERO_DEMO = "jero-demo";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MQ测试队列名字
|
* MQ测试队列名字
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ public class JeroTestFeignController {
|
|||||||
@GetMapping("getMessage2")
|
@GetMapping("getMessage2")
|
||||||
@ApiOperation(value = "测试动态feign", notes = "测试动态feign")
|
@ApiOperation(value = "测试动态feign", notes = "测试动态feign")
|
||||||
public Result<String> getMessage2() {
|
public Result<String> getMessage2() {
|
||||||
JeroTestClientDyn myClientDyn = jeroFeignService.newInstance(JeroTestClientDyn.class, CloudConstant.SERVER_NAME_JeroDemo);
|
JeroTestClientDyn myClientDyn = jeroFeignService.newInstance(JeroTestClientDyn.class, CloudConstant.SERVER_NAME_JERO_DEMO);
|
||||||
return myClientDyn.getMessage("动态fegin——jero-boot2");
|
return myClientDyn.getMessage("动态fegin——jero-boot2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
/**
|
/**
|
||||||
* 常规feign接口定义
|
* 常规feign接口定义
|
||||||
*/
|
*/
|
||||||
@FeignClient(value = CloudConstant.SERVER_NAME_JeroDemo, fallbackFactory = JeroTestClientFallback.class)
|
@FeignClient(value = CloudConstant.SERVER_NAME_JERO_DEMO, fallbackFactory = JeroTestClientFallback.class)
|
||||||
@Component
|
@Component
|
||||||
public interface JeroTestClient {
|
public interface JeroTestClient {
|
||||||
|
|
||||||
|
|||||||
+3
-4
@@ -1,16 +1,14 @@
|
|||||||
package com.jero.modules.cloud.lock;
|
package com.jero.modules.cloud.lock;
|
||||||
|
|
||||||
import com.jero.boot.starter.lock.annotation.JLock;
|
import com.jero.boot.starter.lock.annotation.JLock;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import com.jero.boot.starter.lock.client.RedissonLockClient;
|
import com.jero.boot.starter.lock.client.RedissonLockClient;
|
||||||
import com.jero.boot.starter.rabbitmq.client.RabbitMqClient;
|
import com.jero.boot.starter.rabbitmq.client.RabbitMqClient;
|
||||||
import com.jero.common.base.BaseMap;
|
import com.jero.common.base.BaseMap;
|
||||||
import com.jero.modules.cloud.constant.CloudConstant;
|
import com.jero.modules.cloud.constant.CloudConstant;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,7 +32,7 @@ public class DemoLockTest {
|
|||||||
log.info("执行execute任务开始,休眠三秒");
|
log.info("执行execute任务开始,休眠三秒");
|
||||||
Thread.sleep(3000);
|
Thread.sleep(3000);
|
||||||
log.info("=======================业务逻辑1=============================");
|
log.info("=======================业务逻辑1=============================");
|
||||||
Map map = new BaseMap();
|
Map<String,Object> map = new BaseMap();
|
||||||
map.put("orderId", "BJ0001");
|
map.put("orderId", "BJ0001");
|
||||||
rabbitMqClient.sendMessage(CloudConstant.MQ_JERO_PLACE_ORDER, map);
|
rabbitMqClient.sendMessage(CloudConstant.MQ_JERO_PLACE_ORDER, map);
|
||||||
//延迟10秒发送
|
//延迟10秒发送
|
||||||
@@ -44,6 +42,7 @@ public class DemoLockTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DemoLockTest() {
|
public DemoLockTest() {
|
||||||
|
// do other
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user