Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement zuul Gateway Service in Spring Cloud

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

How to implement zuul gateway service in Spring Cloud? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Zuul project creation

The project creates a cloud-gateway-zuul. Or based on the previous project pom file import

Spring-cloud-alibaba-basis com.xian.cloud 1.0-SNAPSHOT 4.0.0 cloud-gateway-zuul Gateway Service 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

Create a GatewayZuulApplication startup class

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 10:52 on 2019-10-29 * / @ EnableZuulProxy@EnableFeignClients@EnableDiscoveryClient@SpringBootApplicationpublic class GatewayZuulApplication {public static void main (String [] args) {SpringApplication.run (GatewayZuulApplication.class,args);}}

Create bootstrap.yml

Spring: profiles: active: dev application: name: gateway-zuul-server cloud: nacos: config: server-addr: 47.99.209.72 dev application 8848 file-extension: yamlzuul: host: # maximum number of connections to the target host. Default is 200 max-total-connections: 1000 # initial connections per host The default value is 20 max-per-route-connections: 200 routes: discovery-server: path: / server/** serviceId: cloud-discovery-server client-common: path: / client/** serviceId: cloud-discovery-client sensitiveHeaders: the default Hystrix quarantine mode (ExecutionIsolationStrategy) for all routes is SEMAPHORE. If this isolation mode is preferred, zuul.ribbonIsolationStrategy can be changed to the meaning of the attribute THREAD ribbon-isolation-strategy: thread #, specifying the ignored service list * means ignoring all services ignored-services:'*'# fields are sensitive and do not want to be passed to downstream microservices. Set empty sensitive fields that do not want to be ignored. All are passed to the downstream service sensitive-headers: X-ABC ribbon: eager-load: # to force loading. Lazy loading will occur if it is not set. The first request of spring will be very slow enabled: true```# parameter-the maximum number of connections of the zuul.host.max-total-connections target host. -zuul.host.max-per-route-connections the initial number of connections per host. These two parameters are the optimized attribute values of zuul. If you want to have a suitable configuration, you also need to depend on the business situation. Because we have two business services, one service provider and one service consumer, we configure the routing discovery-server of the two services, and client-common- path is the request path matching rule-serviceId is the corresponding value of the spring.application.name of our service. -the sensitiveHeaders field is sensitive and does not want to be passed to downstream micro-services. Set empty sensitive fields that do not want to be ignored. Pass all to downstream services this field can be a global setting or a single service configuration. -the default Hystrix quarantine mode (ExecutionIsolationStrategy) for all ribbon-isolation-strategy routes is SEMAPHORE. If this isolation mode is preferred, zuul.ribbonIsolationStrategy can be changed to THREAD- ignored-services to ignore all microservices and route only the specified microservices. -ribbon.eager-load.enabled true force load false default lazy load true log printing effect false will not print this log `10-29 23 true 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 INFO 47 INFO 11.382 INFO 61396-[main] c.n.l.DynamicServerListLoadBalancer: Using serverListUpdater PollingServerListUpdater2019-10-29 23 INFO 47 main 11.450 INFO 61396-[main] c.netflix.config.ChainedDynamicProperty: Flipping property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 21474836472019-10-29 2323GV 4715 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;]}, 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 INFO 47 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 Switzerland 47Switzerland 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 INFO 47 INFO 61396-[main] c.n.l.DynamicServerListLoadBalancer: Using serverListUpdater PollingServerListUpdater2019-10-29 23 INFO 47 main 11.639 INFO 61396-[main] c.netflix.config.ChainedDynamicProperty: Flipping property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 21474836472019-10-29 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;]}, 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``starts all three services. Service providers and service consumers as well as zuul services enter the command curl http://localhost:9083/client/client/test![file](https://cache.yisu.com/upload/information/20210524/347/785552.png) in the console and we see the print effect, and the request is successfully forwarded to our downstream service through the gateway service. And return-ribbon-isolation-strategy- ignored-services- sensitiveHeaders's answer to the question on how to implement the zuul gateway service in Spring Cloud is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report