Springcloud config + zuul 搭建动态网关
2024-08-27 12:28:10
1,实现的效果,就是zuul 网关的配置路由实现负载均衡,zuul 的配置文件放在springcloud config 上
2,需要的服务如下:
3,其实就是配置下springcloud-zuul 的配置,连接到springcloud-config
maven:在原来的zuul 基础上,加上spring-config-client 和监控中心(手动刷新用的)
<!-- actuator监控中心 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- springcloud config 2.0 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
bootstrap.yml
spring:
application:
####注册中心应用名称
name: service-zuul
cloud:
config:
####读取后缀
profile: dev
####读取config-server注册地址
discovery:
service-id: config-server
enabled: true
#####eureka服务注册地址
eureka:
client:
service-url:
defaultZone: http://localhost:8100/eureka
server:
port: 80 #配置手动实时刷新
#managementendpoints.web.exposure.include=*
management:
endpoints:
web:
exposure:
include: "*"
git 上的配置文件如下:service-zuul-dev-yml
### 配置网关反向代理
zuul:
routes:
api-member:
### 以 /api-member/访问转发到会员服务
path: /api-member/**
serviceId: app-aiyuesheng-member
api-order:
### 以 /api-order/访问转发到订单服务
path: /api-order/**
serviceId: app-aiyuesheng-order
如果配置文件修改了,参照springcloud-config 手动刷新,只不过,他需要在启动类加上这个
@RefreshScope
@ConfigurationProperties("zuul")
public ZuulProperties zuulProperties() {
return new ZuulProperties();
}
再通过post man 发送post 请求:
http://127.0.0.1/actuator/refresh
最新文章
- Windows OS上安装运行Apache Kafka教程
- swift3.0 创建一个app引导页面
- windows下上传文件到VWware的centos
- Android SDK 国内镜像
- Struts中的OGNL和EL表达式笔记
- 静态时序分析(static timing analysis)
- 【转】Android TouchEvent事件传递机制
- 24C01的IIC 讀寫的c51程式
- JavaEE中的MVC(一)Dao层彻底封装
- label按钮和文字对齐
- shell的进度条【转】
- 周一干货~手把手教你安装 Visual Studio 安卓模拟器
- mysql5.7 rpm安装教程
- neo4j---删除关系和节点
- 深度学习原理与框架-RNN网络架构-RNN网络 1.RNN的前向传播 2.RNN的反向传播
- SNP命名
- 树莓派与Arduino Leonardo使用NRF24L01无线模块通信之基于RF24库 (四) 树莓派单子节点查询
- MySQL<;多表操作>;
- JanusGraph Server配置
- [模板]KMP字符串匹配