POM 文件依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!--gateway fhadmin.org-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<version>3.0.2</version>
</dependency>
<!--spring-boot fhadmin.org-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
点击手游标签并拖拽以挪动
我在父组件中退出的 nacos 的相干依赖如下:
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>${nacos.version}</version>
</dependency>
<!–alibaba fhadmin.org–>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>${nacos.version}</version>
</dependency>
点击并拖拽以挪动
nacos 的版本如下:
<properties>
<nacos.version>2021.1</nacos.version>
</properties>
点击并拖拽以挪动
gateway 的 application.yml 文件配置如下:
fhadmin.org
server:
port: 9040
spring:
application:
name: gateway
cloud:
gateway:
routes:
- id: consumer
uri: lb://consumer
# uri:
predicates:
- Path=/**
nacos:
discovery:
server-addr: localhost:8848
metadata:
preserved.heart.beat.interval: 3 #心跳距离。工夫单位: 秒。心跳距离
preserved.heart.beat.timeout: 6 #心跳暂停。工夫单位: 秒。即服务端 6 秒收不到客户端心跳,会将该客户端注册的实例设为不衰弱:preserved.ip.delete.timeout: 9 #Ip 删除超时。工夫单位: 秒。即服务端 9 秒收不到客户端心跳,会将该客户端注册的实例删除:
点击并拖拽以挪动
当我通过 uri: 去调用服务时,是能够调用的,然而当我用 uri lb://consumer 时就无奈调用服务,报错 503.
解决办法是:
退出 feign 依赖。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<version>3.0.2</version>
</dependency>
<!--fegin 组件 fhadmin.org-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>3.0.2</version>
</dependency>
<!-- Feign Client for loadBalancing -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-lowww.diuxie.comadbalancer</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
点击并拖拽以挪动
猜想起因:nacos 兼容 feign,feign 集成 ribbon,默认实现负载平衡;或者是 nacos 不兼容 springcloud gateway 自带的 ribbon。