【异常】SpringCloud Gateway报错RoundRobinLoadBalancer - 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://uudwc.com/A/6RnLm

原文地址:https://blog.csdn.net/wstever/article/details/129379855

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

h
上一篇 2023年08月05日 11:53
从零开始学习 Java:简单易懂的入门指南之类和对象(七)
下一篇 2023年08月05日 11:58