diff --git a/sf-vertx/src/main/java/com/sf/vertx/handle/AppConfigHandler.java b/sf-vertx/src/main/java/com/sf/vertx/handle/AppConfigHandler.java index f81abd6..ba81bdf 100644 --- a/sf-vertx/src/main/java/com/sf/vertx/handle/AppConfigHandler.java +++ b/sf-vertx/src/main/java/com/sf/vertx/handle/AppConfigHandler.java @@ -43,6 +43,7 @@ import io.vertx.core.http.HttpClient; import io.vertx.core.http.HttpMethod; import io.vertx.core.http.HttpServer; import io.vertx.core.http.HttpServerOptions; +import io.vertx.core.net.JksOptions; import io.vertx.core.spi.cluster.ClusterManager; import io.vertx.ext.web.Route; import io.vertx.ext.web.Router; @@ -82,12 +83,13 @@ public class AppConfigHandler { // 负载均衡路由类型 appCode:apiCode - routerType // 执行流程 routerType=
- // 1、serviceNodel="NORMAL", serviceNodel="ROUTE" and RouteType = "WEIGHT_ROUTE"
+ // 1、serviceNodel="NORMAL", serviceNodel="ROUTE" and RouteType = "WEIGHT_ROUTE" + //
// return LOADBALANCING_MAP - // 2、serviceNodel="ROUTE", RouteType = "HEADER_ROUTE"
+ // 2、serviceNodel="ROUTE", RouteType = "HEADER_ROUTE"
// return APICODE_CONFIG_ROUTERCONENT_MAP private static ConcurrentHashMap APICODE_CONFIG_ROUTERTYPE_MAP = new ConcurrentHashMap<>(); - + private static ConcurrentHashMap> APICODE_CONFIG_ROUTERCONENT_MAP = new ConcurrentHashMap<>(); // apiCode熔断配置 appCode:apiCode - CircuitBreaker private static ConcurrentHashMap APICODE_CONFIG_CIRCUIT_BREAKER_MAP = new ConcurrentHashMap<>(); @@ -95,23 +97,22 @@ public class AppConfigHandler { // 禁用appCode private static ConcurrentHashSet DISABLED_APPCODE = new ConcurrentHashSet(); - public static Integer routerType(String key) { return APICODE_CONFIG_ROUTERTYPE_MAP.get(key) != null ? APICODE_CONFIG_ROUTERTYPE_MAP.get(key) : 1; } - + public static List routerConentList(String key) { return APICODE_CONFIG_ROUTERCONENT_MAP.get(key); } - + public static Integer requestModel() { return sacVertxConfig.getRequestModel(); } - + public static String sacResponseHeaderKey() { return sacVertxConfig.getSacResponseHeaderKey(); } - + public static String rpcUri() { return sacVertxConfig.getRpcUri(); } @@ -299,11 +300,11 @@ public class AppConfigHandler { if (appConfig.getAppCurrentLimitingConfig() != null) { initRateLimiter(appCode, appConfig.getAppCurrentLimitingConfig(), GLOBAL_APP_CURRENT_LIMITING_MAP); } - + // app router负载均衡 - int routerType = 1; List routeContentList = null; for (SacService sacService : appConfig.getService()) { + int routerType = 1; List nodeList = new ArrayList<>(); // 获取service模式 if (StringUtils.equals(sacService.getServiceModel(), "NORMAL")) { @@ -338,7 +339,7 @@ public class AppConfigHandler { for (ApiConfig apiConfig : sacService.getApiConfig()) { String key = appCode + ":" + apiConfig.getApiCode(); APICODE_CONFIG_MAP.put(key, apiConfig); - + // 负载均衡模式 APICODE_CONFIG_ROUTERTYPE_MAP.put(key, routerType); switch (routerType) { @@ -480,7 +481,7 @@ public class AppConfigHandler { } }); } - + /*** * 发布消息,订阅消息 * @@ -501,6 +502,10 @@ public class AppConfigHandler { // 创建HTTP监听 // 所有ip都能访问 HttpServerOptions httpServerOptions = new HttpServerOptions().setHost("0.0.0.0"); + if (sacVertxConfig.isSSLs()) { + httpServerOptions.setSsl(true) + .setKeyStoreOptions(new JksOptions().setPassword("changeit").setPath("keystore.jks")); + } HttpServer server = VERTX.createHttpServer(httpServerOptions); Router mainHttpRouter = Router.router(VERTX); Integer serverPort = vertxConfig.getPort() == null ? sacVertxConfig.getPort() : vertxConfig.getPort(); @@ -563,10 +568,9 @@ public class AppConfigHandler { } else { route = mainHttpRouter.route(); } - route.handler(ParameterCheckHandler.create()) - .handler(AppRateLimitHandler.create(rateLimitModel)).handler(ApiRateLimitHandler.create(rateLimitModel)) - .handler(BodyHandler.create()).handler(ProxyHandler.create(mainWebClient, proxy)) - .failureHandler(RestfulFailureHandler.create()); + route.handler(ParameterCheckHandler.create()).handler(AppRateLimitHandler.create(rateLimitModel)) + .handler(ApiRateLimitHandler.create(rateLimitModel)).handler(BodyHandler.create()) + .handler(ProxyHandler.create(mainWebClient, proxy)).failureHandler(RestfulFailureHandler.create()); // mainHttpRouter.route().handler(ProxyHandler.create(mainWebClient, proxy)); } diff --git a/sf-vertx/src/main/java/com/sf/vertx/init/SacVertxConfig.java b/sf-vertx/src/main/java/com/sf/vertx/init/SacVertxConfig.java index f2472bf..2744792 100644 --- a/sf-vertx/src/main/java/com/sf/vertx/init/SacVertxConfig.java +++ b/sf-vertx/src/main/java/com/sf/vertx/init/SacVertxConfig.java @@ -34,6 +34,9 @@ public class SacVertxConfig { @Value("${server.vertx.rpcUri:/rpc}") private String rpcUri; + @Value("${server.vertx.isSSL:false}") + private boolean isSSLs; + @Value("${server.vertx.deploymentMode:1}") private Integer deploymentMode; diff --git a/sf-vertx/src/main/java/com/sf/vertx/utils/ProxyTool.java b/sf-vertx/src/main/java/com/sf/vertx/utils/ProxyTool.java index 61ddaa3..5113e96 100644 --- a/sf-vertx/src/main/java/com/sf/vertx/utils/ProxyTool.java +++ b/sf-vertx/src/main/java/com/sf/vertx/utils/ProxyTool.java @@ -3,8 +3,6 @@ package com.sf.vertx.utils; import java.util.List; import java.util.regex.Pattern; -import org.apache.commons.lang3.StringUtils; - import com.sf.vertx.api.pojo.Node; import com.sf.vertx.api.pojo.RouteContent; import com.sf.vertx.arithmetic.roundRobin.SacLoadBalancing; diff --git a/sf-vertx/src/main/resources/application.yml b/sf-vertx/src/main/resources/application.yml index 0a6405d..adb9c17 100644 --- a/sf-vertx/src/main/resources/application.yml +++ b/sf-vertx/src/main/resources/application.yml @@ -3,12 +3,13 @@ server: vertx: deploymentMode: 1 # 1:单机 2:集群 requestModel: 2 # 1: 客户端传递uri. 2: uri vertx代理,不对客户端暴露uri + isSSL: false # vertx https或者http启动, ssl 证书有过期时间 rpcUri: /rpc sacResponseHeaderKey: sacErrorCode environment: dev server: default: - port: 80 + port: 80 # https端口配置为443 cluster: ip: 127.0.0.1 clusterName: sac-dev diff --git a/sf-vertx/src/main/resources/cacerts.jks b/sf-vertx/src/main/resources/cacerts.jks new file mode 100644 index 0000000..bd8a403 Binary files /dev/null and b/sf-vertx/src/main/resources/cacerts.jks differ diff --git a/sf-vertx/src/main/resources/keystore.jks b/sf-vertx/src/main/resources/keystore.jks new file mode 100644 index 0000000..4da3ff6 Binary files /dev/null and b/sf-vertx/src/main/resources/keystore.jks differ diff --git a/sf-vertx/src/main/resources/server.cer b/sf-vertx/src/main/resources/server.cer new file mode 100644 index 0000000..b9b8a46 Binary files /dev/null and b/sf-vertx/src/main/resources/server.cer differ