当前位置: 代码网 > 科技>操作系统>Windows > 【已解决】Gateway路由转发-报503 Service Unavailable

【已解决】Gateway路由转发-报503 Service Unavailable

2024年08月03日 Windows 我要评论
前端发送的: http://localhost:88/api/captcha.jpg -> 被路由为: http://localhost:8080/api/captcha.jpg。正确的地址应该是: http://localhost:8080/renren-fast/captcha.jpg。服务所在地址,配置没有问题,路径也是对的,但是却报了。前端发送请求到网关, 网关转发到具体的服务,网关路由前端发送获取验证码的请求后。于是使用gateway网关路径重写。为什么会这样,是因为在。版本以后,默认移除了对。


❓1、问题描述

renren-fast框架使用gateway网关路由问题:

gateway网关路由前端发送获取验证码的请求后renren-fastapi失效

前端发送的: http://localhost:88/api/captcha.jpg 通过网关路由->http://localhost:8080/api/captcha.jpg

但是正确地址应该是: http://localhost:8080/renren-fast/captcha.jpg。少了前缀/renren-fastapi应该去掉。

所以使用gateway网关路径重写rewritepath filter实现路由路径正确。

rewritepath=/api/(?<segment>.*),/renren-fast/$\{segment}

实际情况是前端发送请求到网关, 网关路由转发后报如下错误:

503错误: unable to find instance for renren-fast


📚2. 问题分析

首先我们的路由配置如下:

    gateway:
      routes:
        - id: admin_route
          uri: lb://renren-fast
          predicates:
            - path=/api/**
          filters:
            - rewritepath=/api/(?<segment>.*),/renren-fast/$\{segment}

这里使用lb负载均衡路由到renren-fast服务所在地址,配置没有问题,路径也是对的,但是却报了503

在这里插入图片描述

为什么会这样,是因为在spring cloud 2020版本以后,默认移除了对netflix的依赖,其中就包括ribbon,官方默认推荐使用spring cloud loadbalancer正式替换ribbon,并成为了spring cloud负载均衡器的唯一实现。


🚀3. 解决

在当前模块导入spring cloud loadbalancer依赖就可以了。

		<dependency>
			<groupid>org.springframework.cloud</groupid>
			<artifactid>spring-cloud-loadbalancer</artifactid>
		</dependency>

在这里插入图片描述


(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com