Spring Cloud Gateway function module

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/it_lihongmin/article/details/90774723

table of Contents

A, Spring Cloud Gateway Overview and features

Two, Spring Cloud Gateway Integration

Three, Spring Cloud Gateway terminology and works

1, Terminology

2, the working principle

Fourth, routing Predicate factory

V. Filter Factory

Sixth, the global filter

Seven, ssl support

Eight, RouteDefinitionLocator encoding routing configuration

Nine, CORS configuration to achieve cross-domain


A, Spring Cloud Gateway Overview and features

    Before Netflix Zuul Cloud has written the Spring ( Spring Cloud Zuul's Api gateway implementations and Spring Cloud Zuul detailed description of the article) is, Zuul into 1.x and 2.x versions. But first it is sure that Spring Cloud Gateway performance than Zuul, but Gateway based on the Spring 5 , the Spring the Boot 2 and Project Reactor realization (version requirements are relatively high). Spring Cloud Gateway is designed to provide a simple and effective way to route to the api, and provide cross concern for them, such as: security, monitoring / measurement and elasticity.

    characteristic:

Built on Spring 5, Spring Boot 2, Project Reactor

Routing can be performed (of Api gateway) requests

Predicates and Filter special request processing for each route

Hystrix integrated circuit breaker

Spring Cloud registry support

Request frequency limit

Rewrite request (similar to the Nginx)

 

Two, Spring Cloud Gateway Integration

 Start.spring.io added in the gateway module, or add the following dependency in the pom:

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>

Introduced after Sping Cloud Gateway enabled by default gateway associated maven dependent, but may be disposed at bootstrap.properties added (or YML) for closing:

spring.cloud.gateway.enabled=false

Three, Spring Cloud Gateway terminology and works

1, Terminology

Route: route is gateway base module, set by the id, the target uri, Predicate, and set Filter Composition

The Predicate: the Predicate Java8 is a function of the input type of Spring ServerWebExchange, allowing the Http match anything from, or parameters such as the request header.

Filter: Use Spring GatewayFilter Examples of particular plant construction, the request information may be modified before the downstream return or modify the content request occurs after the response to the request (this is consistent with the Zuul filter).

2, the working principle

    The client sends a request to the Spring Cloud Gateway service, if the request can be satisfied and a route map is sent to the Gateway Web Handler, then the service logic processing before the request or after the request based Filter call chain configuration.

Fourth, routing Predicate factory

  1. After Route Predicate Factory
  2. Before Route Predicate Factory
  3. Between Route Predicate Factory
  4. Cookie Route Predicate Factory
  5. Header Route Predicate Factory
  6. Host Route Predicate Factory
  7. Method Route Predicate Factory
  8. Path Route Predicate Factory
  9. Query Route Predicate Factory
  10. RemoteAddr Route Predicate Factory

V. Filter Factory

  1. AddRequestHeader GatewayFilter Factory
  2. AddRequestParameter GatewayFilter Factory
  3. AddResponseHeader GatewayFilter Factory
  4. DedupeResponseHeader GatewayFilter Factory
  5. Hystrix GatewayFilter Factory
  6. FallbackHeaders GatewayFilter Factory
  7. PrefixPath GatewayFilter Factory
  8. PreserveHostHeader GatewayFilter Factory
  9. RequestRateLimiter GatewayFilter Factory
  10. RedirectTo GatewayFilter Factory
  11. RemoveHopByHopHeadersFilter GatewayFilter Factory
  12. RemoveRequestHeader GatewayFilter Factory
  13. RemoveResponseHeader GatewayFilter Factory
  14. RewritePath GatewayFilter Factory
  15. RewriteResponseHeader GatewayFilter Factory
  16. SaveSession GatewayFilter Factory
  17. SecureHeaders GatewayFilter Factory
  18. SetPath GatewayFilter Factory
  19. SetResponseHeader GatewayFilter Factory
  20. SetStatus GatewayFilter Factory
  21. StripPrefix GatewayFilter Factory
  22. Retry GatewayFilter Factory
  23. RequestSize GatewayFilter Factory
  24. Modify Request Body GatewayFilter Factory
  25. Modify Response Body GatewayFilter Factory
  26. Default Filters

 

Sixth, the global filter

  1. Combined Global Filter and GatewayFilter Ordering
  2. Forward Routing Filter
  3. LoadBalancerClient Filter
  4. Netty Routing Filter
  5. Netty Write Response Filter
  6. RouteToRequestUrl Filter
  7. Websocket Routing Filter
  8. Gateway Metrics Filter
  9. Marking An Exchange As Routed

Seven, ssl support

Support is needed to add

Eight, RouteDefinitionLocator encoding routing configuration

    Use RouteDefinitionLocator route, Predicate, Filter arrangement, i.e. can be implemented in two ways, profiles and coding method, as follows:

@Bean
public RouteLocator routeLocator(RouteLocatorBuilder builder) {
    return builder.routes()
        .route(r ->
            r.path("/kevin/**")
            .filters(
                f -> f.stripPrefix(1)
                )
                .uri("http://127.0.0.1:8090/helloWorld")
			)
			.build();
}

Nine, CORS configuration to achieve cross-domain

spring:
  cloud:
    gateway:
      globalcors:
        corsConfigurations:
          '[/**]':
            allowedOrigins: "https://www.kevin.com"
            allowedMethods:
            - GET

About one common solution is similar means Nginx, and gateway services, Spring Cloud Gateway after this configuration, the Get request www.kevin.com services can be cross-domain access, the question as to the relevant cross-domain solutions can be found and I written between cross-domain sharing issues

 

 

 

 

Guess you like

Origin blog.csdn.net/it_lihongmin/article/details/90774723