Spring Cloud zuul a gateway service

Previous comparison Netflix Zuul 1.0 and the gateway. Today to introduce and build the application zuul

Zuul project created

Project to create cloud-gateway-zuul. The project is based on previous
import pom file

 <parent>
        <artifactId>spring-cloud-alibaba-basis</artifactId>
        <groupId>com.xian.cloud</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>cloud-gateway-zuul</artifactId>
    <name>网关服务zuul</name>

    <dependencies>
        <!-- 注册中心 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        <!-- 配置中心 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-nacos-config</artifactId>
        </dependency>
        <!-- fengin 支持 -->
       <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- zuul -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
        </dependency>
    </dependencies>

Create a startup class 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;

/**
 * <Description>
 *
 * @author [email protected]
 * @version 1.0
 * @createDate 2019/10/29 10:52
 */
@EnableZuulProxy
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class GatewayZuulApplication {

    public static void main(String[] args) {
        SpringApplication.run(GatewayZuulApplication.class,args);
    }
}

Creating bootstrap.yml

````
spring:
profiles:
active: dev
application:
name: gateway-zuul-server
cloud:
nacos:
config:
server-addr: 47.99.209.72:8848
file-extension: yaml

Zuul:
Host:
The maximum number of connections the target host #, the default value 200 is
max-Total-Connections: 1000
# Initial number of connections for each host, the default value is 20 is
max-per-route-Connections: 200 is
routes:
Discovery Server- :
path: / Server /
the serviceId: Cloud-Discovery-Server
Client-Common:
path: / Client /

the serviceId: Cloud-Discovery-Client
sensitiveHeaders: X--the ABC, the Authorization
# all default route Hystrix isolation mode (ExecutionIsolationStrategy) is SEMAPHORE. If this is the preferred isolation mode, you can change zuul.ribbonIsolationStrategy THREAD
Ribbon-Isolation-at Strategy: the Thread
# This attribute meaning to ignore the specified list of services * to ignore all service representatives
ignored-services: '*'
sensitive # field, not We want to pass to the downstream micro service. To set an empty no sensitive ignored fields. All passed downstream services
sensitive-headers: the ABC-X-
Ribbon:
the Load-eager:
# forcibly loaded, do not be lazy load settings. spring will be very slow first request
Enabled: to true
`` `

parameter

  • The maximum number of connections zuul.host.max-total-connections of the target host.
  • The initial number of connections zuul.host.max-per-route-connections for each host.

The two parameters are optimized zuul property values, and if you want to have a suitable configuration, also need to be based on business conditions

Because we have both a business service is a service provided by a service consumer of our services are configured both a routing discovery-server, client-common

  • path is the path request matching rule
  • serviceId is spring.application.name the corresponding value of our services.
  • SensitiveHeaders sensitive field, do not want to pass to the downstream micro service. To set an empty no sensitive ignored fields. All passed downstream services in this field can be provided or a single global service configuration.
  • ribbon-isolation-strategy all default route Hystrix isolation mode (ExecutionIsolationStrategy) is SEMAPHORE. If this is the preferred isolation mode, you can change to zuul.ribbonIsolationStrategy THREAD
  • ignored-services ignore all micro-services, only the route specified micro-services.
  • ribbon.eager-load.enabled true false default lazily loaded to force
    • true false log print will not print this log

      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:null
      2019-10-29 23:47:11.382  INFO 61396 --- [           main] c.n.l.DynamicServerListLoadBalancer      : Using serverListUpdater PollingServerListUpdater
      2019-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 = 2147483647
      2019-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@33e4b9c4
      2019-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 = 2147483647
      2019-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:null
      2019-10-29 23:47:11.578  INFO 61396 --- [           main] c.n.l.DynamicServerListLoadBalancer      : Using serverListUpdater PollingServerListUpdater
      2019-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 = 2147483647
      2019-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

All three services will start. Service providers and service consumers have zuul service
in the console enter the command curl http: // localhost: 9083 / client / client / test
file
we saw print, the request was successful forwarded to the gateway service by our downstream services. And return

  • ribbon-isolation-strategy
  • ignored-services
  • sensitiveHeaders

More than a few parameters, as well as the use of routing interceptor zuul services, will be the next one to explain.

How like you can share this concern public number.
file

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement. Reprinted please include public two-dimensional code number

Guess you like

Origin www.cnblogs.com/cloudxlr/p/11762495.html