【异常】SpringCloud Gateway报错503RoundRobinLoadBalancer - No servers available for service: terminal-api

这篇具有很好参考价值的文章主要介绍了【异常】SpringCloud Gateway报错503RoundRobinLoadBalancer - No servers available for service: terminal-api。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、报错内容

2023-03-07 12:07:06.216 [gateway] [boundedElastic-9] WARN  org.springframework.cloud.loadbalancer.core.RoundRobinLoadBalancer - No servers available for service: terminal-api
org.springframework.cloud.gateway.support.NotFoundException: 503 SERVICE_UNAVAILABLE "Unable to find instance for terminal-api"
	at org.springframework.cloud.gateway.support.NotFoundException.create(NotFoundException.java:45)
	Suppressed: The stacktrace has been enhanced by Reactor, refer to additional information below: 
Error has been observed at the following site(s):
	*__checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
	*__checkpoint ⇢ cn.dev33.satoken.reactor.filter.SaReactorFilter [DefaultWebFilterChain]
	*__checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
	*__checkpoint ⇢ HTTP POST "/api/publish" [ExceptionHandlingWebHandler]
Original Stack Trace:
		at org.springframework.cloud.gateway.support.NotFoundException.create(NotFoundException.java:45)
		at org.springframework.cloud.gateway.filter.ReactiveLoadBalancerClientFilter.lambda$filter$2(ReactiveLoadBalancerClientFilter.java:124)
		at reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:185)
		at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:120)
		at reactor.core.publisher.MonoNext$NextSubscriber.onNext(MonoNext.java:82)
		at reactor.core.publisher.FluxDematerialize$DematerializeSubscriber.onNext(FluxDematerialize.java:98)
		at reactor.core.publisher.FluxDematerialize$DematerializeSubscriber.onNext(FluxDematerialize.java:44)
		at reactor.core.publisher.FluxFlattenIterable$FlattenIterableSubscriber.drainAsync(FluxFlattenIterable.java:421)
		at reactor.core.publisher.FluxFlattenIterable$FlattenIterableSubscriber.drain(FluxFlattenIterable.java:686)
		at reactor.core.publisher.FluxFlattenIterable$FlattenIterableSubscriber.onNext(FluxFlattenIterable.java:250)
		at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:74)
		at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1816)
		at reactor.core.publisher.MonoFlatMap$FlatMapInner.onNext(MonoFlatMap.java:249)
		at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.complete(MonoIgnoreThen.java:292)
		at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.onNext(MonoIgnoreThen.java:187)
		at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.subscribeNext(MonoIgnoreThen.java:236)
		at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.onComplete(MonoIgnoreThen.java:203)
		at reactor.core.publisher.MonoIgnoreElements$IgnoreElementsSubscriber.onComplete(MonoIgnoreElements.java:89)
		at reactor.core.publisher.FluxPeek$PeekSubscriber.onComplete(FluxPeek.java:260)
		at reactor.core.publisher.FluxDematerialize$DematerializeSubscriber.onComplete(FluxDematerialize.java:121)
		at reactor.core.publisher.FluxDematerialize$DematerializeSubscriber.onNext(FluxDematerialize.java:91)
		at reactor.core.publisher.FluxDematerialize$DematerializeSubscriber.onNext(FluxDematerialize.java:44)
		at reactor.core.publisher.FluxIterable$IterableSubscription.fastPath(FluxIterable.java:340)
		at reactor.core.publisher.FluxIterable$IterableSubscription.request(FluxIterable.java:227)
		at reactor.core.publisher.FluxDematerialize$DematerializeSubscriber.request(FluxDematerialize.java:127)
		at reactor.core.publisher.FluxPeek$PeekSubscriber.request(FluxPeek.java:138)
		at reactor.core.publisher.MonoIgnoreElements$IgnoreElementsSubscriber.onSubscribe(MonoIgnoreElements.java:72)
		at reactor.core.publisher.FluxPeek$PeekSubscriber.onSubscribe(FluxPeek.java:171)
		at reactor.core.publisher.FluxDematerialize$DematerializeSubscriber.onSubscribe(FluxDematerialize.java:77)
		at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:165)
		at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:87)
		at reactor.core.publisher.Mono.subscribe(Mono.java:4400)
		at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.subscribeNext(MonoIgnoreThen.java:263)
		at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:51)
		at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:157)
		at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1816)
		at reactor.core.publisher.MonoCollectList$MonoCollectListSubscriber.onComplete(MonoCollectList.java:128)
		at reactor.core.publisher.DrainUtils.postCompleteDrain(DrainUtils.java:132)
		at reactor.core.publisher.DrainUtils.postComplete(DrainUtils.java:187)
		at reactor.core.publisher.FluxMaterialize$MaterializeSubscriber.onComplete(FluxMaterialize.java:141)
		at reactor.core.publisher.FluxTake$TakeSubscriber.onComplete(FluxTake.java:153)
		at reactor.core.publisher.FluxTake$TakeSubscriber.onNext(FluxTake.java:133)
		at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java:79)
		at reactor.core.publisher.SerializedSubscriber.onNext(SerializedSubscriber.java:99)
		at reactor.core.publisher.FluxTimeout$TimeoutMainSubscriber.onNext(FluxTimeout.java:180)
		at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1816)
		at reactor.core.publisher.MonoCollectList$MonoCollectListSubscriber.onComplete(MonoCollectList.java:128)
		at org.springframework.cloud.commons.publisher.FluxFirstNonEmptyEmitting$FirstNonEmptyEmittingSubscriber.onComplete(FluxFirstNonEmptyEmitting.java:325)
		at reactor.core.publisher.FluxSubscribeOn$SubscribeOnSubscriber.onComplete(FluxSubscribeOn.java:166)
		at reactor.core.publisher.Operators.complete(Operators.java:137)
		at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:148)
		at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:87)
		at reactor.core.publisher.Flux.subscribe(Flux.java:8469)
		at reactor.core.publisher.FluxFlatMap.trySubscribeScalarMap(FluxFlatMap.java:200)
		at reactor.core.publisher.MonoFlatMapMany.subscribeOrReturn(MonoFlatMapMany.java:49)
		at reactor.core.publisher.Flux.subscribe(Flux.java:8455)
		at reactor.core.publisher.FluxFlatMap.trySubscribeScalarMap(FluxFlatMap.java:200)
		at reactor.core.publisher.MonoFlatMapMany.subscribeOrReturn(MonoFlatMapMany.java:49)
		at reactor.core.publisher.FluxFromMonoOperator.subscribe(FluxFromMonoOperator.java:76)
		at reactor.core.publisher.FluxSubscribeOn$SubscribeOnSubscriber.run(FluxSubscribeOn.java:194)
		at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:84)
		at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:37)
		at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
		at java.util.concurrent.FutureTask.run(FutureTask.java)
		at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
		at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
		at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
		at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
		at java.lang.Thread.run(Thread.java:745)
2023-03-07 12:07:06.236 [gateway] [boundedElastic-9] ERROR chandler.GatewayExceptionHandler - [网关异常处理]请求路径:/api/publish,异常信息:503 SERVICE_UNAVAILABLE "Unable to find instance for terminal-api"

类似报错如下

Load balancer does not contain an instance for the service upms-admin
No servers available for service: joolun-upms-admin

feign 服务间调用异常
feign.FeignException$ServiceUnavailable: [503] during [POST] to [http://upms-admin/loglogin/save] [FeignLogLoginService#saveLogLogin(SysLogLogin,String)]: [Load balancer does not contain an instance for the service joolun-upms-admin]
	at feign.FeignException.serverErrorStatus(FeignException.java:237)
	at feign.FeignException.errorStatus(FeignException.java:180)
	at feign.FeignException.errorStatus(FeignException.java:169)
	at feign.codec.ErrorDecoder$Default.decode(ErrorDecoder.java:92)

类似报错如下

 [503] during [POST] to  [Load balancer does not contain an instance for the service 
{
    "code": 1,
    "msg": "[503] during [POST] to [http://xxx-thirdparty-api/user/selectHrEmpByHrEmp] [FeignHrEmpService#selectHrEmpByHrEmp(HrEmp,String)]: [Load balancer does not contain an instance for the service joolun-thirdparty-api]",
    "data": null,
    "ok": false
}

# 二、报错说明
## 2.1、系统架构说明
terminal-api是一个微服务的子工程,所有请求都经过SpringCloud Gateway。

## 2.2、系统架构图
SpringCloud Gateway对请求进行转发
请求URL包含/api/publish ,已经在拦截器中,直接放行了的。
放行的逻辑如下内容所示:

```java
@Component
@Slf4j
public class ValidateSignFilter extends AbstractGatewayFilterFactory<ValidateSignFilter.Config> {
    private final static String[] VALIDATE_URL = new String[]{"/api/publish"};
    public ValidateSignFilter() {
        super(ValidateSignFilter.Config.class);
    }
    @Override
    public String name() {
        return "ValidateSignFilter";
    }
    @Getter
    @Setter
    static class Config {
        private Integer order;
    }
    @Override
    public GatewayFilter apply(ValidateSignFilter.Config config) {
        return (exchange, chain) -> {
            ServerHttpRequest request = exchange.getRequest();
            if (StringUtils.containsAnyIgnoreCase(request.getURI().getPath(), VALIDATE_URL)) {
                return chain.filter(exchange);
            } 
            //主线校验略
        };
    }
}


引起这个问题的原因有很多, 简要归纳一下:

1.服务名称不能有中划线

2.本地IP地址使用了虚拟网卡地址

3.正常启用了子服务

三、报错解决

3.1 解决方案1

最后排查,因为没有启动有效的terminal-api服务,所以出现了上面的报错。
重新启动terminal-api 即可。

3.2 解决方案2:

虽然在Nacos中看到虽然健康实例,但是其实TA是已经挂了的。

详细看我的文章:Nacos的双写机制。

这个时候,只能从K8s部署微服务的层面,去重启节点了。文章来源地址https://www.toymoban.com/news/detail-775497.html

到了这里,关于【异常】SpringCloud Gateway报错503RoundRobinLoadBalancer - No servers available for service: terminal-api的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Gateway 根据服务名路由失败,报错 Service Unavailable, status=503

    我的SpringBoot版本为2.6.6,本篇文章对于跟我差不多版本的同学应该都适用。 使用gateway+nacos,yaml配置如下,这里使用的是服务名称进行转发: pom文件如下: 然后就出现了服务无法访问的情况,一直报错 This application has no configured error view, so you are seeing this as a fallback. Wed May

    2023年04月08日
    浏览(42)
  • spring cloud gateway中出现503 spring cloud gateway中出现503

    当搭建网关模块的时候出现503的错误的最大的可能就是没有设置负载均衡的依赖包  原先搭建的时候采用的是下面的方式进行设置的 上面的这种方式可以直接进行注册和发现,但是要求必须导入下面的依赖 希望简单的随笔能够帮助你!

    2024年02月11日
    浏览(48)
  • gateway 503无法解决

    2024年01月21日
    浏览(47)
  • spring cloud gateway中出现503

    当搭建网关模块的时候出现503的错误的最大的可能就是没有设置负载均衡的依赖包  原先搭建的时候采用的是下面的方式进行设置的 上面的这种方式可以直接进行注册和发现,但是要求必须导入下面的依赖 希望简单的随笔能够帮助你!

    2024年02月08日
    浏览(55)
  • 【已解决】Gateway路由转发-报503 Service Unavailable

    现象版本 SpringCloud 2021.0.5 Nacos 2.2.0 renren-fast 框架使用 gateway 网关路由问题: gateway 网关路由前端发送获取验证码的请求后 renren-fast 的 api 失效 前端发送的: http://localhost:88/api/captcha.jpg 通过网关路由- http://localhost:8080/api/captcha.jpg 但是正确地址应该是: http://localhost:8080/renren-fas

    2024年01月17日
    浏览(49)
  • SpringCloud GateWay网关整合报错Error creating bean with name ‘routeDefinitionRouteLocator‘ defined in clas

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘routeDefinitionRouteLocator’ defined in class path resource [org/springframework/cloud/gateway/config/GatewayAutoConfiguration.class]: Unsatisfied dependency expressed through method ‘routeDefinitionRouteLocator’ parameter 4; nested exception is org.sprin

    2024年02月13日
    浏览(35)
  • Spring Cloud gateway代理其他服务 503 Service Unavailable

    spring-cloud-alibaba + Spring Cloud gateway + nacos 通过gateway反问其他服务时出现 503 Service Unavailable,spring-cloud的版本为2021.0.4,spring-cloud-alibaba的版本为2021.0.4.0。 解决方法:由于spring-cloud 2020版本以后移除了Netflix依赖,其中的ribbon也被移除,所以我们手动引入ribbon的替代依赖库即可,这

    2024年02月16日
    浏览(59)
  • 关于spring cloud gateway中出现503 Service Unavailable的问题

    1.引用spring cloud gateway+nacos配置中心 2.微服务+分布式(本节与分布式问题无关)项目 3.路由规则:网关端口:8085;第三方端口:8081,8086 第三方单独访问路径localhost:8081/test/getUserTest?id=2 希望路由到:localhost:consumer-service/test/getUserTest?id=2 (这里我写了两个消费者服务,服务名一致

    2024年02月01日
    浏览(54)
  • Nacos和GateWay路由转发NotFoundException: 503 SERVICE_UNAVAILABLE “Unable to find

    2023-08-15 16:51:16,151 DEBUG [reactor-http-nio-2][CompositeLog.java:147] - [dc73b32c-1] Encoding [{timestamp=Tue Aug 15 16:51:16 CST 2023, path=/content/course/list, status=503, error=Service Unavai (truncated)...] 2023-08-15 16:51:16,175 TRACE [reactor-http-nio-2][GatewayMetricsFilter.java:115] - gateway.requests tags: [tag(httpMethod=POST),tag(httpStatusC

    2024年02月12日
    浏览(63)
  • 【异常】客户端发起HTTPS请求报错,服务端返回400 Bad Request ,并且提示No required SSL certificate was sent

    HTTP响应码400表示客户端发送了一个无效的请求。这可能是由于请求中缺少必需的参数或格式不正确等原因导致的。服务器无法处理此请求并返回400响应码。如果您正在编写Web应用程序,建议在处理请求时检查请求的有效性,并在必要时返回400响应码以指示客户端请求无效。

    2024年02月11日
    浏览(49)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包