一、报错内容
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的双写机制。文章来源:https://www.toymoban.com/news/detail-775497.html
这个时候,只能从K8s部署微服务的层面,去重启节点了。文章来源地址https://www.toymoban.com/news/detail-775497.html
到了这里,关于【异常】SpringCloud Gateway报错503RoundRobinLoadBalancer - No servers available for service: terminal-api的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!