Nacos和GateWay路由转发NotFoundException: 503 SERVICE_UNAVAILABLE “Unable to find

这篇具有很好参考价值的文章主要介绍了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上都已经成功注册上了两个服务

Nacos和GateWay路由转发NotFoundException: 503 SERVICE_UNAVAILABLE “Unable to find,杂谈,gateway,java,服务器

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

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

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

server:
  servlet:
    context-path: /content
  port: 63040

test_config:
 a: 3a
 b: 3b

#配置本地优先
spring:
 cloud:
  config:
    override-none: true
#微服务配置
spring:
  application:
    name: content-api
  cloud:
    nacos:
      server-addr: 192.168.101.65:8848
      discovery:
        namespace: ${spring.profiles.active}
        group: EducationPlatform
        username: nacos
        password: nacos
      config:
        namespace: ${spring.profiles.active}
        group: EducationPlatform
        file-extension: yaml
        refresh-enabled: true
        extension-configs:
          - data-id: content-service-${spring.profiles.active}.yaml
            group: EducationPlatform
            refresh: true
        shared-configs:
          - data-id: swagger-${spring.profiles.active}.yaml
            group: EducationPlatform-common
            refresh: true
          - data-id: logging-${spring.profiles.active}.yaml
            group: EducationPlatform-common
            refresh: true
  profiles:
    active: dev11

 而发送了一个这个请求

Nacos和GateWay路由转发NotFoundException: 503 SERVICE_UNAVAILABLE “Unable to find,杂谈,gateway,java,服务器

问题解决:

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

Nacos和GateWay路由转发NotFoundException: 503 SERVICE_UNAVAILABLE “Unable to find,杂谈,gateway,java,服务器

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

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的作用就是区分不同类型的配置文件,进行分组管理

Nacos和GateWay路由转发NotFoundException: 503 SERVICE_UNAVAILABLE “Unable to find,杂谈,gateway,java,服务器

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

Nacos和GateWay路由转发NotFoundException: 503 SERVICE_UNAVAILABLE “Unable to find,杂谈,gateway,java,服务器

Nacos和GateWay路由转发NotFoundException: 503 SERVICE_UNAVAILABLE “Unable to find,杂谈,gateway,java,服务器

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

重启服务即可

 Nacos和GateWay路由转发NotFoundException: 503 SERVICE_UNAVAILABLE “Unable to find,杂谈,gateway,java,服务器文章来源地址https://www.toymoban.com/news/detail-651335.html

到了这里,关于Nacos和GateWay路由转发NotFoundException: 503 SERVICE_UNAVAILABLE “Unable to find的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索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日
    浏览(26)
  • gateway路由转发

    今天学习的时候看到yml中有关与gateway的配置没看懂 然后就去网上学习了一下,分享我一下我的学习成果吧, gateway可以开启从注册中心转发路由 然后就是有一个routes的配置 这边的 predicates 就是你访问gateway路由端口后的路径,类似于我访问 http://localhost:gateway端口/case/api/sys

    2024年02月12日
    浏览(23)
  • Gateway路由转发,报404错误

    项目使用SpringCloud分为多个微服务,在使用Gateway进行路由转发时,找不到对应的微服务模块,导致返回404报错。 当用户发出请求达到 GateWay 之后,会通过一些匹配条件,定位到真正的服务节点,而 Predicate就是匹配条件 。当满足条件后才会进行转发路由,如果是多个,那么

    2024年02月11日
    浏览(30)
  • 三分钟了解Spring Cloud Gateway路由转发之自动路由

    大家好,我是冰点,今天和大家分享一下关于Spring Cloud Gateway 利用服务注册与发现实现自动路由的原理和源码解读。希望对大家有所帮助。 今天有个新同学,问我 为什么我们的网关服务Spring Cloud Gateway,没有配置路由就可以将请求到路由服务 ,说他们之前的项目的网关是将

    2024年02月08日
    浏览(26)
  • gateway+nacos动态路由配置

    spring cloud微服务场景下,需要使用到路由转发组。本文将从3个方面介绍路由配置: 简单的场景 通过nacos动态路由配置 常用配置属性 我使用的版本: 各组件版本尽量与这个一致,版本参考: https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E 配置gateway路由前

    2024年02月09日
    浏览(32)
  • Gateway基于Nacos动态路由实现

    客户端请求,首先会被 Gateway Handler Mapping 处理,用以在  路由表  中查找一个与请求匹配的  路由 , 然后将请求交由  Web Handler  处理, Web Handler  维护了一个过滤器链,链式执行这些过滤器,这些过滤器在逻辑上存在两个执行阶段  pre   与  post   Nacos 致力于帮助您发现

    2024年02月06日
    浏览(24)
  • 5.微服务项目实战---Gateway--服务网关,实现统一认证、鉴权、监控、路由转发等

    大家都都知道在微服务架构中,一个系统会被拆分为很多个微服务。那么作为客户端要如何去调用 这么多的微服务呢?如果没有网关的存在,我们只能在客户端记录每个微服务的地址,然后分别去调用。   这样的架构,会存在着诸多的问题: 客户端多次请求不同的微服务,

    2024年02月16日
    浏览(33)
  • SpringCloud Gateway的使用 + Nacos动态路由

    一、简介 1、什么是gateway? SpringCloud Gateway是spring官方基于Spring 5.0、Spring Boot2.0和Project Reactor等技术开发的网关,旨在为微服务架构提供简单、有效和统一的API路由管理方式 SpringCloud Gateway作为SpringCloud生态系统中的网关,目标是替代Netflix Zuul,在SpringCloud 2.0以上版本中,没有

    2024年02月03日
    浏览(30)
  • SpringCloud nacos 集成 gateway ,实现动态路由

    🎈 作者: Linux猿 🎈 简介: CSDN博客专家🏆,华为云享专家🏆,Linux、C/C++、云计算、物联网、面试、刷题、算法尽管咨询我,关注我,有问题私聊! 🎈 欢迎小伙伴们点赞👍、收藏⭐、留言💬 目录 一、准备工作 1.1 下载代码 1.2 运行代码 二、集成 gateway 2.1 修改 pom.xml 2

    2024年02月16日
    浏览(26)
  • springcloud3 GateWay章节-Nacos+gateway动态路由负载均衡4

    1.pom文件 2.启动类 3.配置文件 1.启动nacos,sleuth 2.启动gatewayapi,mscloud-nacos-provider7001,mscloud-nacos-provider7002 如图: 3.访问 多次刷新:7001和7002 不停的切换

    2024年02月11日
    浏览(27)

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

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

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

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

二维码1

领取红包

二维码2

领红包