From cea8fbba7b526ca459edeffcbb121f0aa6da7fdb Mon Sep 17 00:00:00 2001 From: tanghc Date: Fri, 22 Nov 2019 15:49:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E6=8E=92=E9=99=A4=E5=85=B6=E5=AE=83?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/docs/_sidebar.md | 66 +++++++++---------- doc/docs/files/90100_常见问题.md | 9 +++ .../manager/EnvironmentKeys.java | 8 ++- .../route/BaseRegistryListener.java | 17 ++++- 4 files changed, 65 insertions(+), 35 deletions(-) diff --git a/doc/docs/_sidebar.md b/doc/docs/_sidebar.md index 4a8a6951..d72faede 100644 --- a/doc/docs/_sidebar.md +++ b/doc/docs/_sidebar.md @@ -1,35 +1,35 @@ -* [首页](/?t=1573711393653) +* [首页](/?t=1574408534264) * 开发文档 - * [快速体验](files/10010_快速体验.md?t=1573711393655) - * [项目接入到SOP](files/10011_项目接入到SOP.md?t=1573711393680) - * [新增接口](files/10020_新增接口.md?t=1573711393680) - * [开发流程](files/10021_开发流程.md?t=1573711393680) - * [业务参数校验](files/10030_业务参数校验.md?t=1573711393680) - * [错误处理](files/10040_错误处理.md?t=1573711393680) - * [编写文档](files/10041_编写文档.md?t=1573711393680) - * [接口交互详解](files/10050_接口交互详解.md?t=1573711393680) - * [easyopen支持](files/10070_easyopen支持.md?t=1573711393681) - * [使用签名校验工具](files/10080_使用签名校验工具.md?t=1573711393681) - * [ISV管理](files/10085_ISV管理.md?t=1573711393681) - * [自定义返回结果](files/10087_自定义返回结果.md?t=1573711393681) - * [自定义过滤器](files/10088_自定义过滤器.md?t=1573711393681) - * [自定义校验token](files/10089_自定义校验token.md?t=1573711393681) - * [路由授权](files/10090_路由授权.md?t=1573711393681) - * [接口限流](files/10092_接口限流.md?t=1573711393682) - * [监控日志](files/10093_监控日志.md?t=1573711393682) - * [SDK开发](files/10095_SDK开发.md?t=1573711393682) - * [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1573711393682) - * [应用授权](files/10097_应用授权.md?t=1573711393682) - * [提供restful接口](files/10100_提供restful接口.md?t=1573711393682) - * [文件上传](files/10104_文件上传.md?t=1573711393682) - * [配置Sleuth链路追踪](files/10109_配置Sleuth链路追踪.md?t=1573711393683) - * [预发布灰度发布](files/10110_预发布灰度发布.md?t=1573711393683) - * [动态修改请求参数](files/10111_动态修改请求参数.md?t=1573711393683) - * [使用eureka](files/10112_使用eureka.md?t=1573711393683) - * [扩展其它注册中心](files/10113_扩展其它注册中心.md?t=1573711393683) + * [快速体验](files/10010_快速体验.md?t=1574408534265) + * [项目接入到SOP](files/10011_项目接入到SOP.md?t=1574408534281) + * [新增接口](files/10020_新增接口.md?t=1574408534281) + * [开发流程](files/10021_开发流程.md?t=1574408534281) + * [业务参数校验](files/10030_业务参数校验.md?t=1574408534281) + * [错误处理](files/10040_错误处理.md?t=1574408534281) + * [编写文档](files/10041_编写文档.md?t=1574408534282) + * [接口交互详解](files/10050_接口交互详解.md?t=1574408534282) + * [easyopen支持](files/10070_easyopen支持.md?t=1574408534282) + * [使用签名校验工具](files/10080_使用签名校验工具.md?t=1574408534282) + * [ISV管理](files/10085_ISV管理.md?t=1574408534282) + * [自定义返回结果](files/10087_自定义返回结果.md?t=1574408534282) + * [自定义过滤器](files/10088_自定义过滤器.md?t=1574408534282) + * [自定义校验token](files/10089_自定义校验token.md?t=1574408534282) + * [路由授权](files/10090_路由授权.md?t=1574408534282) + * [接口限流](files/10092_接口限流.md?t=1574408534282) + * [监控日志](files/10093_监控日志.md?t=1574408534282) + * [SDK开发](files/10095_SDK开发.md?t=1574408534283) + * [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1574408534283) + * [应用授权](files/10097_应用授权.md?t=1574408534283) + * [提供restful接口](files/10100_提供restful接口.md?t=1574408534283) + * [文件上传](files/10104_文件上传.md?t=1574408534283) + * [配置Sleuth链路追踪](files/10109_配置Sleuth链路追踪.md?t=1574408534283) + * [预发布灰度发布](files/10110_预发布灰度发布.md?t=1574408534283) + * [动态修改请求参数](files/10111_动态修改请求参数.md?t=1574408534283) + * [使用eureka](files/10112_使用eureka.md?t=1574408534283) + * [扩展其它注册中心](files/10113_扩展其它注册中心.md?t=1574408534283) * 原理分析 - * [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1573711393683) - * [原理分析之如何存储路由](files/90011_原理分析之如何存储路由.md?t=1573711393683) - * [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1573711393683) - * [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1573711393684) - * [常见问题](files/90100_常见问题.md?t=1573711393684) + * [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1574408534283) + * [原理分析之如何存储路由](files/90011_原理分析之如何存储路由.md?t=1574408534283) + * [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1574408534283) + * [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1574408534284) + * [常见问题](files/90100_常见问题.md?t=1574408534284) diff --git a/doc/docs/files/90100_常见问题.md b/doc/docs/files/90100_常见问题.md index 0a970c6f..7bcc2b33 100644 --- a/doc/docs/files/90100_常见问题.md +++ b/doc/docs/files/90100_常见问题.md @@ -112,3 +112,12 @@ spring.cloud.nacos.discovery.metadata.server.servlet.context-path=${server.servl ``` 不然网关无法拉取路由信息 + +## 其它微服务没有开放接口,需要排除 + +在sop-gateway项目中配置 + +```properties +# 排除服务,多个用,隔开 +sop.service.exclude=your-serviceId1,your-serviceId2 +``` diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/EnvironmentKeys.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/EnvironmentKeys.java index 3590c040..7ef06db6 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/EnvironmentKeys.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/EnvironmentKeys.java @@ -26,7 +26,13 @@ public enum EnvironmentKeys { /** * sop.restful.path=/xx ,指定请求前缀,默认/rest */ - SOP_RESTFUL_PATH("sop.restful.path", "/rest"); + SOP_RESTFUL_PATH("sop.restful.path", "/rest"), + + /** + * 排除其它微服务,多个用英文逗号隔开 + */ + SOP_SERVICE_EXCLUDE("sop.service.exclude") + ; private String key; private String defaultValue; diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/BaseRegistryListener.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/BaseRegistryListener.java index 5fc35061..260f7e3b 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/BaseRegistryListener.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/BaseRegistryListener.java @@ -1,10 +1,13 @@ package com.gitee.sop.gatewaycommon.route; import com.gitee.sop.gatewaycommon.bean.InstanceDefinition; +import com.gitee.sop.gatewaycommon.manager.EnvironmentKeys; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -50,7 +53,8 @@ public abstract class BaseRegistryListener implements RegistryListener { } protected boolean canOperator(String serviceId) { - for (String excludeServiceId : EXCLUDE_SERVICE_ID_LIST) { + List excludeServiceIdList = getExcludeServiceId(); + for (String excludeServiceId : excludeServiceIdList) { if (excludeServiceId.equalsIgnoreCase(serviceId)) { return false; } @@ -65,4 +69,15 @@ public abstract class BaseRegistryListener implements RegistryListener { } return can; } + + private List getExcludeServiceId() { + String excludeServiceIds = EnvironmentKeys.SOP_SERVICE_EXCLUDE.getValue(); + List excludeServiceIdList = new ArrayList<>(8); + if (StringUtils.isNotBlank(excludeServiceIds)) { + String[] serviceIdArr = excludeServiceIds.split(","); + excludeServiceIdList.addAll(Arrays.asList(serviceIdArr)); + } + excludeServiceIdList.addAll(EXCLUDE_SERVICE_ID_LIST); + return excludeServiceIdList; + } }