登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
模力方舟
登录
注册
代码拉取完成,页面将自动刷新
开源项目
>
开发工具
>
开发/调试
&&
WEB应用开发
>
WebUI组件/框架
&&
捐赠
捐赠前请先登录
取消
前往登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
788
Star
7K
Fork
1.4K
GVP
萧明
/
knife4j
代码
Issues
229
Pull Requests
7
Wiki
统计
流水线
服务
JavaDoc
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
SBOM
我知道了,不再自动展开
更新失败,请稍后重试!
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
Knife4J Aggregation 2.0.8 集成Nacos的问题
已完成
#I2KUUY
TeRny
创建于
2021-01-24 17:38
> JDK版本:AdoptOpenJDK 11.0.7 x64 hotspot > Knife4J版本:2.0.8 > SpringBoot版本:2.3.8.RELEASE > SpringCloud Alibaba版本:2.2.4.RELEASE > SpringCloud 版本:Hoxton.SR8 生产项目大部分微服务都在使用Nacos,微服务需要对文档进行聚合。早期一直都是在Gateway服务中去聚合其它服务。现在Knife4J出了**Aggregation Starter**,理念非常OK,但实际上基本无法应用于Nacos,主要存在的问题如下: ## 问题一、不支持Nacos认证 在如今信息安全要求如此之高的年代,不可能将Nacos裸奔,但将Nacos中的`application.properties`文件添加以下配置: ```shell nacos.core.auth.enabled=true ``` 之后,Nacos就需要使用用户名和密码登录,但这样就造成了Knife4J Aggregation无法正常使用。 2个月前也有 [Issue I28IF9](https://gitee.com/xiaoym/knife4j/issues/I28IF9) 在说,期待下个版本解决。 ## 问题二、不支持上下文 为确保Gateway网关转发的服务上下文一致,通常会给每个服务配置上下文: ```yaml server: port: 8200 servlet: context-path: /doc-service # 上下文配置 knife4j: enableAggregation: true nacos: enable: true serviceUrl: http://${spring.cloud.nacos.discovery.server-addr}/nacos routes: - name: 认证服务 serviceName: auth-service location: /v2/api-docs?group=default servicePath: /auth-service namespaceId: fw6 groupName: DEFAULT_GROUP ``` 然后再通过以下类似的Gateway网关配置去访问服务: ```yaml spring: cloud: gateway: discovery: locator: lower-case-service-id: true # 将请求路径上的服务名配置为小写 routes: # 固定路由 - id: 认证服务 uri: lb://auth-service # 转发到负载均衡 predicates: - Path=/auth-service/** # 匹配哪些路径 filters: - StripPrefix=0 # 不截取前缀 - PreserveHostHeader # 发送原始请求的主机头 - id: 文档服务 uri: lb://doc-service # 转发到负载均衡,但实际会被拦截,uri参数必写 predicates: - Path=/doc-service/** # 匹配哪些路径 filters: - StripPrefix=0 - PreserveHostHeader # 发送原始请求的主机头 ``` 然后通过网关访问文档服务,例如:`http://localhost:9000/doc-service/doc.html`,打开的是空白页面,例如:  同时,控制台打印: ```shell 2021-01-24 17:29:11.457 INFO 19468 --- [http-nio-8200-exec-1] com.github.xiaoymin.knife4j.aggre.core.filter.Knife4jRouteProxyFilter.doFilter:51 : Current Request:/doc-service/v2/api-docs 2021-01-24 17:29:11.457 INFO 19468 --- [http-nio-8200-exec-1] com.github.xiaoymin.knife4j.aggre.core.filter.Knife4jRouteProxyFilter.doFilter:52 : 当前请求是Proxy请求 2021-01-24 17:29:11.458 INFO 19468 --- [http-nio-8200-exec-1] com.github.xiaoymin.knife4j.aggre.core.RouteDispatcher.buildContext:228 : 目标请求Url:http://localhost:8100/v2/api-docs,请求类型:GET,Host:localhost 2021-01-24 17:29:11.461 INFO 19468 --- [http-nio-8200-exec-1] com.github.xiaoymin.knife4j.aggre.core.executor.ApacheClientExecutor.buildRequest:36 : ApacheClient Uri:http://localhost:8100/v2/api-docs 2021-01-24 17:29:11.471 INFO 19468 --- [http-nio-8200-exec-1] com.github.xiaoymin.knife4j.aggre.core.RouteDispatcher.writeResponseHeader:149 : 响应类型:text/html;charset=utf-8,响应编码:UTF-8 2021-01-24 17:29:11.474 INFO 19468 --- [http-nio-8200-exec-1] com.github.xiaoymin.knife4j.aggre.core.filter.Knife4jRouteProxyFilter.doFilter:54 : 执行完毕 ``` 从以上打印的内容,发现Knife4J Aggregation打开的*认证服务*的URL为`http://localhost:8100/v2/api-docs`,该地址无上下文`auth-service`,正确的地址应该为`http://localhost:8100/auth-service/v2/api-docs` ## 问题三、不能过滤健康的服务 Knife4J Aggregation会用到多个服务的聚合,比例20个服务。但其中只要有1个服务宕机,就会导致整个Knife4J Aggregation空白。[Issue I2CKQT](https://gitee.com/xiaoym/knife4j/issues/I2CKQT) 同时在反馈,期待下个版本解决
> JDK版本:AdoptOpenJDK 11.0.7 x64 hotspot > Knife4J版本:2.0.8 > SpringBoot版本:2.3.8.RELEASE > SpringCloud Alibaba版本:2.2.4.RELEASE > SpringCloud 版本:Hoxton.SR8 生产项目大部分微服务都在使用Nacos,微服务需要对文档进行聚合。早期一直都是在Gateway服务中去聚合其它服务。现在Knife4J出了**Aggregation Starter**,理念非常OK,但实际上基本无法应用于Nacos,主要存在的问题如下: ## 问题一、不支持Nacos认证 在如今信息安全要求如此之高的年代,不可能将Nacos裸奔,但将Nacos中的`application.properties`文件添加以下配置: ```shell nacos.core.auth.enabled=true ``` 之后,Nacos就需要使用用户名和密码登录,但这样就造成了Knife4J Aggregation无法正常使用。 2个月前也有 [Issue I28IF9](https://gitee.com/xiaoym/knife4j/issues/I28IF9) 在说,期待下个版本解决。 ## 问题二、不支持上下文 为确保Gateway网关转发的服务上下文一致,通常会给每个服务配置上下文: ```yaml server: port: 8200 servlet: context-path: /doc-service # 上下文配置 knife4j: enableAggregation: true nacos: enable: true serviceUrl: http://${spring.cloud.nacos.discovery.server-addr}/nacos routes: - name: 认证服务 serviceName: auth-service location: /v2/api-docs?group=default servicePath: /auth-service namespaceId: fw6 groupName: DEFAULT_GROUP ``` 然后再通过以下类似的Gateway网关配置去访问服务: ```yaml spring: cloud: gateway: discovery: locator: lower-case-service-id: true # 将请求路径上的服务名配置为小写 routes: # 固定路由 - id: 认证服务 uri: lb://auth-service # 转发到负载均衡 predicates: - Path=/auth-service/** # 匹配哪些路径 filters: - StripPrefix=0 # 不截取前缀 - PreserveHostHeader # 发送原始请求的主机头 - id: 文档服务 uri: lb://doc-service # 转发到负载均衡,但实际会被拦截,uri参数必写 predicates: - Path=/doc-service/** # 匹配哪些路径 filters: - StripPrefix=0 - PreserveHostHeader # 发送原始请求的主机头 ``` 然后通过网关访问文档服务,例如:`http://localhost:9000/doc-service/doc.html`,打开的是空白页面,例如:  同时,控制台打印: ```shell 2021-01-24 17:29:11.457 INFO 19468 --- [http-nio-8200-exec-1] com.github.xiaoymin.knife4j.aggre.core.filter.Knife4jRouteProxyFilter.doFilter:51 : Current Request:/doc-service/v2/api-docs 2021-01-24 17:29:11.457 INFO 19468 --- [http-nio-8200-exec-1] com.github.xiaoymin.knife4j.aggre.core.filter.Knife4jRouteProxyFilter.doFilter:52 : 当前请求是Proxy请求 2021-01-24 17:29:11.458 INFO 19468 --- [http-nio-8200-exec-1] com.github.xiaoymin.knife4j.aggre.core.RouteDispatcher.buildContext:228 : 目标请求Url:http://localhost:8100/v2/api-docs,请求类型:GET,Host:localhost 2021-01-24 17:29:11.461 INFO 19468 --- [http-nio-8200-exec-1] com.github.xiaoymin.knife4j.aggre.core.executor.ApacheClientExecutor.buildRequest:36 : ApacheClient Uri:http://localhost:8100/v2/api-docs 2021-01-24 17:29:11.471 INFO 19468 --- [http-nio-8200-exec-1] com.github.xiaoymin.knife4j.aggre.core.RouteDispatcher.writeResponseHeader:149 : 响应类型:text/html;charset=utf-8,响应编码:UTF-8 2021-01-24 17:29:11.474 INFO 19468 --- [http-nio-8200-exec-1] com.github.xiaoymin.knife4j.aggre.core.filter.Knife4jRouteProxyFilter.doFilter:54 : 执行完毕 ``` 从以上打印的内容,发现Knife4J Aggregation打开的*认证服务*的URL为`http://localhost:8100/v2/api-docs`,该地址无上下文`auth-service`,正确的地址应该为`http://localhost:8100/auth-service/v2/api-docs` ## 问题三、不能过滤健康的服务 Knife4J Aggregation会用到多个服务的聚合,比例20个服务。但其中只要有1个服务宕机,就会导致整个Knife4J Aggregation空白。[Issue I2CKQT](https://gitee.com/xiaoym/knife4j/issues/I2CKQT) 同时在反馈,期待下个版本解决
评论 (
2
)
登录
后才可以发表评论
状态
已完成
待办的
进行中
已完成
已关闭
负责人
未设置
标签
enhancement
未设置
标签管理
里程碑
Knife4j 2.0.9版本
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
分支 (19)
标签 (44)
dev
dependabot/npm_and_yarn/knife4j-doc/cross-spawn-7.0.6
dependabot/npm_and_yarn/knife4j-doc/http-proxy-middleware-2.0.7
dependabot/npm_and_yarn/knife4j-doc/multi-9f37c16f8f
dependabot/maven/knife4j-insight/commons-io-commons-io-2.14.0
dependabot/npm_and_yarn/knife4j-front/knife4j-ui-react/rollup-3.29.5
dependabot/npm_and_yarn/knife4j-front/knife4j-ui-react/vite-4.5.5
dependabot/npm_and_yarn/knife4j-doc/multi-cf87d80143
dependabot/npm_and_yarn/knife4j-doc/multi-d66d039ac5
dependabot/npm_and_yarn/knife4j-doc/multi-9423f4c335
dependabot/npm_and_yarn/knife4j-doc/webpack-5.94.0
dependabot/npm_and_yarn/knife4j-doc/micromatch-4.0.8
master
v2
backup_dev_202208
backup_v2_202208
backup_master_202208
1.4
1.3
v4.5.0
v4.4.0
v4.3.0
v4.2.0
v4.1.0
v4.0.0
v2.0.9
v2.0.8
v2.0.7
v2.0.6
v2.0.5
v2.0.4
v2.0.3
v2.0.2
v2.0.1
v2.0.0
v1.9.6
v1.9.5
v1.9.4
v1.9.3
v1.9.2
v1.9.1
v1.9.0
v1.8.9
v1.8.8
v1.8.7
v1.8.6
v1.8.5
v1.8.4
v1.8.3
v1.8.2
v1.8.1
v1.8.0
v1.7.9
v1.7.8
v1.7.7
v1.7.6
v1.7.5
v1.7.3
v1.7.2
v1.3
1.2
1.1
v1.0
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
参与者(1)
Java
1
https://gitee.com/xiaoym/knife4j.git
git@gitee.com:xiaoym/knife4j.git
xiaoym
knife4j
knife4j
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册