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(httpStatusCode=503),tag(outcome=SERVER_ERROR),tag(routeId=content-api),tag(routeUri=lb://content-api),tag(status=SERVICE_UNAVAILABLE)]
2023-08-15 16:51:16,187 DEBUG [reactor-http-nio-2][Loggers.java:254] - [id: 0xdc73b32c, L:/127.0.0.1:63010 - R:/127.0.0.1:53113] Decreasing pending responses, now 0
2023-08-15 16:51:16,190 DEBUG [reactor-http-nio-2][Loggers.java:249] - [id: 0xdc73b32c, L:/127.0.0.1:63010 - R:/127.0.0.1:53113] Last HTTP packet was sent, terminating the channel
2023-08-15 16:51:16,192 DEBUG [reactor-http-nio-2][LogFormatUtils.java:91] - [dc73b32c-1] Completed 503 SERVICE_UNAVAILABLE
2023-08-15 16:51:16,195 DEBUG [reactor-http-nio-2][Loggers.java:249] - [id: 0xdc73b32c, L:/127.0.0.1:63010 - R:/127.0.0.1:53113] Last HTTP response frame
2023-08-15 16:51:16,203 DEBUG [reactor-http-nio-2][Loggers.java:254] - [id: 0xdc73b32c, L:/127.0.0.1:63010 - R:/127.0.0.1:53113] FluxReceive{pending=0, cancelled=true, inboundDone=false, inboundError=null}: dropping frame DefaultLastHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 53, cap: 53/53, unwrapped: PooledUnsafeDirectByteBuf(ridx: 296, widx: 296, cap: 2048)), decoderResult: success)
2023-08-15 16:51:16,205 DEBUG [reactor-http-nio-2][Loggers.java:259] - [id: 0xdc73b32c, L:/127.0.0.1:63010 - R:/127.0.0.1:53113] onUncaughtException(SimpleConnection{channel=[id: 0xdc73b32c, L:/127.0.0.1:63010 - R:/127.0.0.1:53113]})
java.io.IOException: 远程主机强迫关闭了一个现有的连接。
    at sun.nio.ch.SocketDispatcher.read0(Native Method)
    at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
    at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
    at sun.nio.ch.IOUtil.read(IOUtil.java:192)
    at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:379)
    at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:253)
    at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1134)
    at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.lang.Thread.run(Thread.java:750)
2023-08-15 16:51:16,432 DEBUG [com.alibaba.nacos.naming.failover][FailoverReactor.java:147] - failover switch is not found, failover00-00---000-VIPSRV_FAILOVER_SWITCH-000---00-00
2023-08-15 16:51:17,002 DEBUG [PollingServerListUpdater-0][PropertySourcesPropertyResolver.java:115] - Found key 'spring.profiles.active' in PropertySource 'configurationProperties' with value of type String
2023-08-15 16:51:17,003 DEBUG [PollingServerListUpdater-0][HostReactor.java:306] - failover-mode: false
2023-08-15 16:51:17,003 DEBUG [PollingServerListUpdater-0][DynamicServerListLoadBalancer.java:241] - List of Servers for content-api obtained from Discovery client: []
2023-08-15 16:51:17,003 DEBUG [PollingServerListUpdater-0][DynamicServerListLoadBalancer.java:246] - Filtered List of Servers for content-api obtained from Discovery client: []

问题前提的环境配置:

首先我的nacos上都已经成功注册上了两个服务

其中Gateway的nacos上的配置和本地的配置分别为

server:port: 63010 # 网关端口
spring:cloud:gateway:discovery:locator:lowerCaseServiceId: true# 让gateway根据注册中心找到其他服务enabled: trueroutes: - id: content-api # 路由id,自定义,只要唯一即可uri: lb://content-api # 路由的目标地址 lb就是负载均衡,后面跟服务名称predicates: # 路由断言,也就是判断请求是否符合路由规则的条件- Path=/content/** # 这个是按照路径匹配,只要以/content/开头就符合要求- id: system-apiuri: lb://system-apipredicates:- Path=/system/**
#微服务配置
spring:application:name: gatewaycloud:nacos:server-addr: 192.168.101.65:8848discovery:namespace: ${spring.profiles.active}group: EducationPlatform-projectconfig:namespace: ${spring.profiles.active}group: EducationPlatform-projectfile-extension: yamlrefresh-enabled: trueshared-configs:- data-id: logging-${spring.profiles.active}.yamlgroup: EducationPlatform-commonrefresh: trueprofiles:active: dev11

而content-api的nacos上的配置和本地的配置分别为

server:servlet:context-path: /contentport: 63040test_config:a: 3ab: 3b#配置本地优先
spring:cloud:config:override-none: true
#微服务配置
spring:application:name: content-apicloud:nacos:server-addr: 192.168.101.65:8848discovery:namespace: ${spring.profiles.active}group: EducationPlatformusername: nacospassword: nacosconfig:namespace: ${spring.profiles.active}group: EducationPlatformfile-extension: yamlrefresh-enabled: trueextension-configs:- data-id: content-service-${spring.profiles.active}.yamlgroup: EducationPlatformrefresh: trueshared-configs:- data-id: swagger-${spring.profiles.active}.yamlgroup: EducationPlatform-commonrefresh: true- data-id: logging-${spring.profiles.active}.yamlgroup: EducationPlatform-commonrefresh: trueprofiles:active: dev11

 而发送了一个这个请求

问题解决:

首先可以在idea里快速的按两下shift,然后搜这个方法名,打个断点看看方法能不能送到这里来,可以看到我这的uri已经是有了的,证明配置和服务都没有问题,问题缩小到路由转发出了问题。

其次这两个问题报错也让我们要注意的问题就是转发问题

Zone aware logic disabled or there is only one zone

NotFoundException: 503 SERVICE_UNAVAILABLE "Unable to find instance for content-api

一、pom配置

因为路由转发配置上用到了lb:,这个是负载均衡的标志,而在Spring Cloud 2020版本以后,就移除了Ribbon负载均衡器,官方默认推荐使用Spring Cloud Loadbalancer正式替换Ribbon。因此我们需要把Spring Cloud Loadbalancer加载到pom里面

<!--客户端负载均衡loadbalancer--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-loadbalancer</artifactId><optional>true</optional></dependency>

实在不行的再加载这两个 

        <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency>

二、小细节

我是加上了pom都还不行的,而后面发现我的group是不同的,在nacos中group的作用就是区分不同类型的配置文件,进行分组管理

 相同Data Id而不同Group的意义就在相当于相同的目录下不同的文件,不同group直接的服务调用是只能通过额外config里配置

 因此解决办法就是把nacos中的group的后缀都改成-project,本地配置中的也改了然后实在不行的话Gateway配置上再添加上lowerCaseServiceId: true

重启服务即可

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/73571.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Mathematica(42)-计算N个数值的和

比如&#xff0c;我们要用Mathematica求得到下面的式子&#xff1a; 这就需要用到一个函数&#xff1a;Sum 具体地&#xff0c;Sum函数的使用形式如下&#xff1a; 因此&#xff0c;按照公式就可以得到下面的结果&#xff1a; 如果&#xff0c;我们想要将求和号也加进去&#…

Java 项目日志实例基础:Log4j

点击下方关注我&#xff0c;然后右上角点击...“设为星标”&#xff0c;就能第一时间收到更新推送啦~~~ 介绍几个日志使用方面的基础知识。 1 Log4j 1、Log4j 介绍 Log4j&#xff08;log for java&#xff09;是 Apache 的一个开源项目&#xff0c;通过使用 Log4j&#xff0c;我…

Windows10上VS2022单步调试FFmpeg 4.2源码

之前在 https://blog.csdn.net/fengbingchun/article/details/103735560 介绍过通过VS2017单步调试FFmpeg源码的方法&#xff0c;这里在Windows10上通过VS2022单步调试FFmpeg 4.2的方法&#xff1a;基于GitHub上ShiftMediaProject/FFmpeg项目&#xff0c;下面对编译过程进行说明…

http库 之 OKHttpUtil

源码位置 方便实用&#xff0c;个人感觉不错 依赖 <dependency><groupId>io.github.admin4j</groupId><artifactId>common-http-starter</artifactId><version>0.7.5</version> </dependency>代码实践 /*** 通用http的pos…

飞天使-k8s简单搭建(编写中)

文章目录 k8s概念安装部署-第一版无密钥配置与hosts与关闭swap开启ipv4转发安装前启用脚本开启ip_vs安装指定版本docker 安装kubeadm kubectl kubelet,此部分为基础构建模版 k8s一主一worker节点部署k8s三个master部署,如果负载均衡keepalived 不可用&#xff0c;可以用单节点做…

数据挖掘 | 零代码采集房源数据,支持自动翻页、数据排重等

1 前言 城市规划、商业选址等应用场景中经常会对地区房价、地域价值进行数据分析&#xff0c;其中地区楼盘房价是分析数据中重要的信息参考点&#xff0c;一些互联网网站上汇聚了大量房源信息&#xff0c;通过收集此类数据&#xff0c;能够对地区房价的分析提供参考依据。 如何…

无脑入门pytorch系列(四)—— scatter_

本系列教程适用于没有任何pytorch的同学&#xff08;简单的python语法还是要的&#xff09;&#xff0c;从代码的表层出发挖掘代码的深层含义&#xff0c;理解具体的意思和内涵。pytorch的很多函数看着非常简单&#xff0c;但是其中包含了很多内容&#xff0c;不了解其中的意思…

ansible入门

ansible入门 一.ansible 背景介绍 Ansible 是一个广受欢迎的 IT 自动化系统。可以用来处理配置管理、应用自动化部署、云资源配给、网络 自动化和多借点部署等任务。其也可以使得复杂的变更如带负载均衡的零停机滚动更新更加容易。Ansible.com 1.1 自动化运维概念 1.1.1 运维…

Linux0.11内核源码解析-truncate.c

truncate文件只要实现释放指定i节点在设备上占用的所有逻辑块&#xff0c;包括直接块、一次间接块、二次间接块。从而将文件节点对应的文件长度截为0&#xff0c;并释放占用的设备空间。 索引节点的逻辑块连接方式 释放一次间接块 static void free_ind(int dev,int block) {…

关于Linux Docker springboot jar 日志时间不正确 问题解决

使用Springboot项目的jar&#xff0c;制作了一个Docker镜像&#xff0c;启动该镜像后发现容器和容器中的Springboot 项目的日志时间不正确。 解决 查看容器时间命令为&#xff1a; docker exec 容器id date 1. 容器与宿主机同步时间 在启动镜像时候把操作系统的时间通过&q…

爬虫逆向实战(八)--猿人学第十五题

一、数据接口分析 主页地址&#xff1a;猿人学第十五题 1、抓包 通过抓包可以发现数据接口是api/match/15 2、判断是否有加密参数 请求参数是否加密&#xff1f; 查看“载荷”模块可以发现有一个m加密参数 请求头是否加密&#xff1f; 无响应是否加密&#xff1f; 无cook…

汽车领域专业术语

1. DMS/OMS/RMS/IMS DMS&#xff1a;即Driver Monitoring System&#xff0c;监测对象为Driver&#xff08;驾驶员&#xff09;。DMS三大核心&#xff1a; OMS&#xff1a;即Occupancy Monitoring System&#xff0c;监测对象为乘客。 RMS&#xff1a;后排盲区检测系统 IMS&…