Chinaunix首页 | 论坛 | 博客
  • 博客访问: 614239
  • 博文数量: 298
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 3077
  • 用 户 组: 普通用户
  • 注册时间: 2019-06-17 10:57
文章分类

全部博文(298)

文章存档

2022年(96)

2021年(201)

2019年(1)

我的朋友

分类: Java

2021-12-28 10:48:45


点击(此处)折叠或打开

  1. POM文件依赖

  2. <dependencies>
  3.     <dependency>
  4.         <groupId>org.springframework.boot</groupId>
  5.         <artifactId>spring-boot-starter</artifactId>
  6.     </dependency>

  7.     <dependency>
  8.         <groupId>org.springframework.cloud</groupId>
  9.         <artifactId>spring-cloud-starter-gateway</artifactId>
  10.         <version>3.0.2</version>
  11.     </dependency>

  12.     <dependency>
  13.         <groupId>org.springframework.boot</groupId>
  14.         <artifactId>spring-boot-starter-test</artifactId>
  15.         <scope>test</scope>
  16.     </dependency>
  17. </dependencies>
  18. nacos的版本如下:

  19. <properties>
  20.     <nacos.version>2021.1</nacos.version>
  21. </properties>
  22. gateway的application.yml文件配置如下:

  23. //fhadmin.cn
  24. server:
  25.   port: 9040

  26. spring:
  27.   application:
  28.     name: gateway
  29.   cloud:
  30.     gateway:
  31.       routes:
  32.         - id: consumer
  33.           uri: lb://consumer
  34.           # uri: http://localhost:9010
  35.           predicates:
  36.             - Path=/**
  37.     nacos:
  38.       discovery:
  39.         server-addr: localhost:8848
  40.         metadata:
  41.           preserved.heart.beat.interval: 3 #心跳间隔。时间单位:秒。心跳间隔
  42.           preserved.heart.beat.timeout: 6 #心跳暂停。时间单位:秒。 即服务端6秒收不到客户端心跳,会将该客户端注册的实例设为不健康:
  43.           preserved.ip.delete.timeout: 9 #Ip删除超时。时间单位:秒。即服务端9秒收不到客户端心跳,会将该客户端注册的实例删除:
  44. 当我通过uri: http://localhost:9010去调用服务时,是可以调用的,但是当我用uri lb://consumer时就无法调用服务,报错503.

  45. 解决办法是:
  46. 加入feign依赖。
  47. <dependencies>
  48.     <dependency>
  49.         <groupId>org.springframework.boot</groupId>
  50.         <artifactId>spring-boot-starter</artifactId>
  51.     </dependency>

  52.     <dependency>
  53.         <groupId>org.springframework.cloud</groupId>
  54.         <artifactId>spring-cloud-starter-gateway</artifactId>
  55.         <version>3.0.2</version>
  56.     </dependency>

  57.     <!--fegin组件-->
  58.     <dependency>
  59.         <groupId>org.springframework.cloud</groupId>
  60.         <artifactId>spring-cloud-starter-openfeign</artifactId>
  61.         <version>3.0.2</version>
  62.     </dependency>
  63.     <!-- Feign Client for loadBalancing -->
  64.     <dependency>
  65.         <groupId>org.springframework.cloud</groupId>
  66.         <artifactId>spring-cloud-loadbalancer</artifactId>
  67.         <version>3.0.2</version>
  68.     </dependency>

  69.     <dependency>
  70.         <groupId>org.springframework.boot</groupId>
  71.         <artifactId>spring-boot-starter-test</artifactId>
  72.         <scope>test</scope>
  73.     </dependency>
  74. </dependencies>
  75. 猜测原因:nacos兼容feign,feign集成ribbon,默认实现负载均衡;或许是nacos不兼容springcloud gateway自带的ribbon。实现案例 fhadmin.cn

阅读(2209) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~