1. gateway 引入 nacos 依赖,实现服务的注册发现

2. gateway 引入 loadbalancer 依赖,实现服务的负载均衡
This commit is contained in:
YunaiV 2022-06-02 23:43:34 +08:00
parent 9bb0422c1c
commit 94d62b8d79
5 changed files with 33 additions and 7 deletions

View File

@ -12,6 +12,7 @@
}, },
"gateway": { "gateway": {
"baseUrl": "http://127.0.0.1:8888/admin-api", "baseUrl": "http://127.0.0.1:8888/admin-api",
"systemBaseUrl": "http://127.0.0.1:8888/admin-api",
"token": "test1", "token": "test1",
"adminTenentId": "1", "adminTenentId": "1",

View File

@ -16,11 +16,24 @@
<url>https://github.com/YunaiV/yudao-cloud</url> <url>https://github.com/YunaiV/yudao-cloud</url>
<dependencies> <dependencies>
<!-- 引入 Spring Cloud Gateway 相关依赖,使用它作为网关,并实现对其的自动配置 --> <!-- Gateway 网关相关 -->
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId> <artifactId>spring-cloud-starter-gateway</artifactId>
</dependency> </dependency>
<!-- RPC 远程调用相关 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<!-- Registry 注册中心相关 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -4,10 +4,10 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class YudaoGatewayApplication { public class GatewayServerApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(YudaoGatewayApplication.class, args); SpringApplication.run(GatewayServerApplication.class, args);
} }
} }

View File

@ -0,0 +1,9 @@
server:
port: 8888
--- #################### 注册中心相关配置 ####################
spring:
cloud:
nacos:
server-addr: 127.0.0.1:8848

View File

@ -1,7 +1,10 @@
server:
port: 8888
spring: spring:
application:
name: gateway-server
profiles:
active: local
cloud: cloud:
# Spring Cloud Gateway 配置项,对应 GatewayProperties 类 # Spring Cloud Gateway 配置项,对应 GatewayProperties 类
gateway: gateway:
@ -20,6 +23,6 @@ spring:
filters: # 过滤器,对请求进行拦截,实现自定义的功能,对应 FilterDefinition 数组 filters: # 过滤器,对请求进行拦截,实现自定义的功能,对应 FilterDefinition 数组
- StripPrefix=1 - StripPrefix=1
- id: system-admin-api # 路由的编号 - id: system-admin-api # 路由的编号
uri: http://127.0.0.1:48080 # 路由的目标地址 uri: lb://system-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组 predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin-api/system/** - Path=/admin-api/system/**