首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring Cloud Gateway无法负载均衡,返回500错误

Spring Cloud Gateway无法负载均衡,返回500错误
EN

Stack Overflow用户
提问于 2020-02-12 17:03:21
回答 1查看 3.3K关注 0票数 1

我在这里遵循教程:https://www.javainuse.com/spring/cloud-gateway-eureka

我有两个应用程序,可以通过localhost访问(localhost:8080/employee/messages,localhost:8082/consumer/messages)。我还有一个服务发现(Spring Cloud Eureka)和用于负载均衡的Spring Cloud Gateway。我已经在eureka上注册了所有这三个。

另外,我在本地机器上运行所有的东西,这里的host.docker.internal是什么?

网关应用程序的application.properties文件如下所示:

代码语言:javascript
复制
server:
  port: 9090

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8083/eureka  

spring:
  application:
    name: gateway-service
  cloud:
    gateway:
      routes:
      - id: employeeModule
        uri: lb://FIRST-SERVICE
        predicates:
        - Path=/employee/**
      - id: consumerModule
        uri: lb://SECOND-SERVICE
        predicates:
        - Path=/consumer/**

但是,每当我尝试访问localhost:9090/employee/message时,我都会得到错误代码500。网关服务中的错误日志如下所示:

代码语言:javascript
复制
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further information: host.docker.internal/10.7.250.57:8080
Caused by: java.net.ConnectException: Connection timed out: no further information
        at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na]
        at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:579) ~[na:na]
        at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:820) ~[na:na]
        at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:327) ~[netty-transport-4.1.38.Final.jar!/:4.1.38.Final]
        at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:336) ~[netty-transport-4.1.38.Final.jar!/:4.1.38.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:685) ~[netty-transport-4.1.38.Final.jar!/:4.1.38.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:632) ~[netty-transport-4.1.38.Final.jar!/:4.1.38.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:549) ~[netty-transport-4.1.38.Final.jar!/:4.1.38.Final]
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:511) ~[netty-transport-4.1.38.Final.jar!/:4.1.38.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:918) ~[netty-common-4.1.38.Final.jar!/:4.1.38.Final]
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.38.Final.jar!/:4.1.38.Final]
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.38.Final.jar!/:4.1.38.Final]
        at java.base/java.lang.Thread.run(Thread.java:830) ~[na:na]

有人能告诉我这里的错误是什么吗?

编辑:我在企业代理服务器后面,无法执行以下操作: curl host.docker.internal:8080/employee/message

EN

回答 1

Stack Overflow用户

发布于 2020-05-20 01:47:39

该消息告诉您,您没有从网关连接到微服务REST端点。您的URI似乎没有正确指定;建议使用uri:http://localhost:8000/employee之类的URL或类似的内容。(在我的应用程序中工作...)

至于负载均衡,在这篇文章中没有负载均衡。Spring Cloud Gateway根据您的请求属性匹配路由。这就是您在yml文件中试图简化的内容。Spring Cloud Gateway并不等同于负载均衡,它是微服务架构的入口。

负载均衡要么使用Netflix Ribbon (显然已被弃用),要么使用新的Spring Cloud Load Balancer。您没有使用任何一个,因此没有负载均衡。例如,请参阅:

https://spring.io/blog/2020/03/25/spring-tips-spring-cloud-loadbalancer

https://spring.io/guides/gs/spring-cloud-loadbalancer/

此外,您还需要设置可以在本地或跨网络发现的并行应用程序。然后实现Netflix Ribbon,或者最好实现新的Spring负载均衡器。

我相信,对于非常高流量的应用程序,可以设置并行的Spring Cloud Gateway,并在这些网关之间进行负载均衡。我更希望一个网关不是高流量的瓶颈,即使它是异步的,就像这里的情况一样。

我还没有发现任何跨网关的负载均衡的例子,我希望在这里得到反馈。具体地说,与Spring文档(正在发展)中的Hello应用程序不同,是否有特定于跨网关的负载平衡的东西?

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60184580

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档