Spring Cloud中怎么实现zuul网关服务
发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,Spring Cloud中怎么实现zuul网关服务,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。Zuul 工程创建工程创建 clou
千家信息网最后更新 2025年12月02日Spring Cloud中怎么实现zuul网关服务
Spring Cloud中怎么实现zuul网关服务,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
Zuul 工程创建
工程创建 cloud-gateway-zuul。还是基于之前的工程 pom文件导入
spring-cloud-alibaba-basis com.xian.cloud 1.0-SNAPSHOT 4.0.0 cloud-gateway-zuul 网关服务zuul com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery com.alibaba.cloud spring-cloud-alibaba-nacos-config org.springframework.cloud spring-cloud-starter-openfeign org.springframework.boot spring-boot-starter-test test org.springframework.cloud spring-cloud-starter-netflix-zuul
创建GatewayZuulApplication启动类
package com.xian.cloud;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;import org.springframework.cloud.netflix.zuul.EnableZuulProxy;import org.springframework.cloud.openfeign.EnableFeignClients;/** ** * @author xianliru@100tal.com * @version 1.0 * @createDate 2019/10/29 10:52 */@EnableZuulProxy@EnableFeignClients@EnableDiscoveryClient@SpringBootApplicationpublic class GatewayZuulApplication { public static void main(String[] args) { SpringApplication.run(GatewayZuulApplication.class,args); }}
创建 bootstrap.yml
spring: profiles: active: dev application: name: gateway-zuul-server cloud: nacos: config: server-addr: 47.99.209.72:8848 file-extension: yamlzuul: host: # 目标主机的最大连接数,默认值为200 max-total-connections: 1000 # 每个主机的初始连接数,默认值为20 max-per-route-connections: 200 routes: discovery-server: path: /server/** serviceId: cloud-discovery-server client-common: path: /client/** serviceId: cloud-discovery-client sensitiveHeaders: X-ABC,Authorization # 所有路由的默认Hystrix隔离模式(ExecutionIsolationStrategy)为SEMAPHORE。如果此隔离模式是首选,则zuul.ribbonIsolationStrategy可以更改为THREAD ribbon-isolation-strategy: thread # 这个属性意思,指定忽略的服务列表 * 代表忽略所有服务 ignored-services: '*' # 字段比较敏感,不希望传递给下游微服务。 设置空没有要忽略的敏感字段。全部传给下游服务 sensitive-headers: X-ABC ribbon: eager-load: # 强制加载,不设置会进行懒加载。spring 第一次请求会非常慢 enabled: true```#### 参数- zuul.host.max-total-connections 目标主机的最大连接数。- zuul.host.max-per-route-connections 每个主机的初始连接数。这个俩个参数是zuul的优化后的属性值,如果想有适合的配置,还需要根据业务情况而定因为我们有俩个业务服务 一个服务提供者 一个是服务消费者我们配置俩个服务的分别路由 discovery-server、client-common- path 是请求路径匹配规则- serviceId 是我们服务的spring.application.name 对应的值。- sensitiveHeaders 字段比较敏感,不希望传递给下游微服务。 设置空没有要忽略的敏感字段。全部传给下游服务这个字段可以是全局设置也可以是单个服务配置。- ribbon-isolation-strategy 所有路由的默认Hystrix隔离模式(ExecutionIsolationStrategy)为SEMAPHORE。如果此隔离模式是首选,则zuul.ribbonIsolationStrategy可以更改为THREAD- ignored-services 忽略所有微服务,只路由指定的微服务。- ribbon.eager-load.enabled true 强制加载 false 默认懒加载true日志打印效果 false 将不打印这段日志```2019-10-29 23:47:11.377 INFO 61396 --- [ main] c.netflix.loadbalancer.BaseLoadBalancer : Client: cloud-discovery-server instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=cloud-discovery-server,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null2019-10-29 23:47:11.382 INFO 61396 --- [ main] c.n.l.DynamicServerListLoadBalancer : Using serverListUpdater PollingServerListUpdater2019-10-29 23:47:11.450 INFO 61396 --- [ main] c.netflix.config.ChainedDynamicProperty : Flipping property: cloud-discovery-server.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 21474836472019-10-29 23:47:11.452 INFO 61396 --- [ main] c.n.l.DynamicServerListLoadBalancer : DynamicServerListLoadBalancer for client cloud-discovery-server initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=cloud-discovery-server,current list of Servers=[192.168.3.6:9012],Load balancer stats=Zone stats: {unknown=[Zone:unknown; Instance count:1; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;]},Server stats: [[Server:192.168.3.6:9012; Zone:UNKNOWN; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 08:00:00 CST 1970; First connection made: Thu Jan 01 08:00:00 CST 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0]]}ServerList:com.alibaba.cloud.nacos.ribbon.NacosServerList@33e4b9c42019-10-29 23:47:11.576 INFO 61396 --- [ main] c.netflix.config.ChainedDynamicProperty : Flipping property: cloud-discovery-client.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 21474836472019-10-29 23:47:11.577 INFO 61396 --- [ main] c.netflix.loadbalancer.BaseLoadBalancer : Client: cloud-discovery-client instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=cloud-discovery-client,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null2019-10-29 23:47:11.578 INFO 61396 --- [ main] c.n.l.DynamicServerListLoadBalancer : Using serverListUpdater PollingServerListUpdater2019-10-29 23:47:11.639 INFO 61396 --- [ main] c.netflix.config.ChainedDynamicProperty : Flipping property: cloud-discovery-client.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 21474836472019-10-29 23:47:11.640 INFO 61396 --- [ main] c.n.l.DynamicServerListLoadBalancer : DynamicServerListLoadBalancer for client cloud-discovery-client initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=cloud-discovery-client,current list of Servers=[192.168.3.6:9011],Load balancer stats=Zone stats: {unknown=[Zone:unknown; Instance count:1; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;]},Server stats: [[Server:192.168.3.6:9011; Zone:UNKNOWN; Total Requests:0; Successive connection failure:0; Total blackout seconds:0; Last connection made:Thu Jan 01 08:00:00 CST 1970; First connection made: Thu Jan 01 08:00:00 CST 1970; Active Connections:0; total failure count in last (1000) msecs:0; average resp time:0.0; 90 percentile resp time:0.0; 95 percentile resp time:0.0; min resp time:0.0; max resp time:0.0; stddev resp time:0.0]]}ServerList:com.alibaba.cloud.nacos.ribbon.NacosServerList@256589a1```将三个服务全部启动。服务提供者和服务消费者还有zuul 服务在控制台 输入命令 curl http://localhost:9083/client/client/test我们看到打印效果,请求通过网关服务成功转发到了我们的下游服务上。并返回- ribbon-isolation-strategy- ignored-services- sensitiveHeaders关于Spring Cloud中怎么实现zuul网关服务问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注行业资讯频道了解更多相关知识。
服务
字段
网关
主机
模式
路由
隔离
工程
问题
配置
最大
业务
参数
属性
提供者
效果
日志
更多
消费者
目标
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
怎样分辨服务器内存和台式旧内存
苹果数据库怎么检索
三级数据库上机题库
张家港互联网软件开发方法
网络技术标准设计规范大全
简述数据库管理技术的发展简史
传统软件开发把软件开发
网络安全十大工程五大任务
阿里云服务器特点
网络安全软件开发设计
服务器管理功能错误
医疗信息数据库的常见安全威胁
复翼软件开发年报
租了服务器怎么做网站
数据库关联表 bll
俄罗斯国家安全战略网络安全
数据库语句选出前五的数据
未来无界网络技术有限公司口碑
二级数据库用什么软件考
怎样手动添加服务器地址
web调用数据库时间失败
vcc服务器
云服务器的系统软件
网络安全保卫总队付茂琼
网络安全与网络隐私讲座感悟
数据库合并列表
江苏统一软件开发设施检测中心
医疗用数据库
开展网红网络安全宣传
以数据库为基础的信息技术