Talk about GatewayControllerEndpoint of springcloud

  springcloud

Order

This article mainly studies the GatewayControllerEndpoint of springcloud.

GatewayAutoConfiguration

spring-cloud-gateway-core-2.0.0.RC1-sources.jar! /org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java

@Configuration
@ConditionalOnProperty(name = "spring.cloud.gateway.enabled", matchIfMissing = true)
@EnableConfigurationProperties
@AutoConfigureBefore(HttpHandlerAutoConfiguration.class)
@AutoConfigureAfter({GatewayLoadBalancerClientAutoConfiguration.class, GatewayClassPathWarningAutoConfiguration.class})
@ConditionalOnClass(DispatcherHandler.class)
public class GatewayAutoConfiguration {
    //......
    @Configuration
    @ConditionalOnClass(Health.class)
    protected static class GatewayActuatorConfiguration {

        @Bean
        @ConditionalOnEnabledEndpoint
        public GatewayControllerEndpoint gatewayControllerEndpoint(RouteDefinitionLocator routeDefinitionLocator, List<GlobalFilter> globalFilters,
                                                                List<GatewayFilterFactory> GatewayFilters, RouteDefinitionWriter routeDefinitionWriter,
                                                                RouteLocator routeLocator) {
            return new GatewayControllerEndpoint(routeDefinitionLocator, globalFilters, GatewayFilters, routeDefinitionWriter, routeLocator);
        }
    }
}

It can be seen that there is a GatewayActuatorConfiguration at the end, which will be configured under the premise of having an actuator class library. The configuration is GatewayControllerEndpoint.

GatewayControllerEndpoint

spring-cloud-gateway-core-2.0.0.RC1-sources.jar! /org/springframework/cloud/gateway/actuate/GatewayControllerEndpoint.java

The following restapis are provided

  • POST /refresh
  • GET /globalfilters
  • GET /routefilters
  • GET /routes
  • POST /routes/{id}
  • GET /routes/{id}
  • GET /routes/{id}/combinedfilters

Example

/actuator/gateway/routes

[
  {
    "route_id": "CompositeDiscoveryClient_DISCOVERY-SERVICE",
    "route_definition": {
      "id": "CompositeDiscoveryClient_DISCOVERY-SERVICE",
      "predicates": [
        {
          "name": "Path",
          "args": {
            "pattern": "/DISCOVERY-SERVICE/**"
          }
        }
      ],
      "filters": [
        {
          "name": "RewritePath",
          "args": {
            "regexp": "/DISCOVERY-SERVICE/(?<remaining>.*)",
            "replacement": "/${remaining}"
          }
        }
      ],
      "uri": "lb://DISCOVERY-SERVICE",
      "order": 0
    },
    "order": 0
  },
  {
    "route_id": "CompositeDiscoveryClient_GATEWAY-SERVICE",
    "route_definition": {
      "id": "CompositeDiscoveryClient_GATEWAY-SERVICE",
      "predicates": [
        {
          "name": "Path",
          "args": {
            "pattern": "/GATEWAY-SERVICE/**"
          }
        }
      ],
      "filters": [
        {
          "name": "RewritePath",
          "args": {
            "regexp": "/GATEWAY-SERVICE/(?<remaining>.*)",
            "replacement": "/${remaining}"
          }
        }
      ],
      "uri": "lb://GATEWAY-SERVICE",
      "order": 0
    },
    "order": 0
  }
]

/actuator/gateway/globalfilters

{
  "org.springframework.cloud.gateway.filter.LoadBalancerClientFilter@f425231": 10100,
  "org.springframework.cloud.gateway.filter.NettyWriteResponseFilter@5cbd94b2": -1,
  "org.springframework.cloud.gateway.filter.NettyRoutingFilter@506aabf6": 2147483647,
  "org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter@756aadfc": 10000,
  "org.springframework.cloud.gateway.filter.ForwardRoutingFilter@705a8dbc": 2147483647,
  "org.springframework.cloud.gateway.filter.AdaptCachedBodyGlobalFilter@6824b913": 2147483637,
  "org.springframework.cloud.gateway.filter.WebsocketRoutingFilter@40729f01": 2147483646
}

/actuator/gateway/routefilters

{
  "[RedirectToGatewayFilterFactory@32f96bba configClass = RedirectToGatewayFilterFactory.Config]": null,
  "[StripPrefixGatewayFilterFactory@4a481728 configClass = StripPrefixGatewayFilterFactory.Config]": null,
  "[RemoveResponseHeaderGatewayFilterFactory@67e25252 configClass = AbstractGatewayFilterFactory.NameConfig]": null,
  "[RequestHeaderToRequestUriGatewayFilterFactory@4ace284d configClass = AbstractGatewayFilterFactory.NameConfig]": null,
  "[ModifyRequestBodyGatewayFilterFactory@b3e86d5 configClass = ModifyRequestBodyGatewayFilterFactory.Config]": null,
  "[RemoveRequestHeaderGatewayFilterFactory@611640f0 configClass = AbstractGatewayFilterFactory.NameConfig]": null,
  "[SetStatusGatewayFilterFactory@3fd05b3e configClass = SetStatusGatewayFilterFactory.Config]": null,
  "[PreserveHostHeaderGatewayFilterFactory@4d0e54e0 configClass = Object]": null,
  "[SetResponseHeaderGatewayFilterFactory@1682c08c configClass = AbstractNameValueGatewayFilterFactory.NameValueConfig]": null,
  "[SecureHeadersGatewayFilterFactory@76ececd configClass = Object]": null,
  "[SaveSessionGatewayFilterFactory@4eb9f2af configClass = Object]": null,
  "[AddResponseHeaderGatewayFilterFactory@75b6dd5b configClass = AbstractNameValueGatewayFilterFactory.NameValueConfig]": null,
  "[PrefixPathGatewayFilterFactory@e111c7c configClass = PrefixPathGatewayFilterFactory.Config]": null,
  "[SetRequestHeaderGatewayFilterFactory@7affc159 configClass = AbstractNameValueGatewayFilterFactory.NameValueConfig]": null,
  "[RewritePathGatewayFilterFactory@58f4b31a configClass = RewritePathGatewayFilterFactory.Config]": null,
  "[SetPathGatewayFilterFactory@72eb6200 configClass = SetPathGatewayFilterFactory.Config]": null,
  "[RetryGatewayFilterFactory@21a9a705 configClass = RetryGatewayFilterFactory.Retry]": null,
  "[AddRequestHeaderGatewayFilterFactory@1f1cddf3 configClass = AbstractNameValueGatewayFilterFactory.NameValueConfig]": null,
  "[ModifyResponseBodyGatewayFilterFactory@72b43104 configClass = ModifyResponseBodyGatewayFilterFactory.Config]": null,
  "[AddRequestParameterGatewayFilterFactory@228bda54 configClass = AbstractNameValueGatewayFilterFactory.NameValueConfig]": null
}

/actuator/gateway/routes/CompositeDiscoveryClient_DISCOVERY-SERVICE

{
  "id": "CompositeDiscoveryClient_DISCOVERY-SERVICE",
  "predicates": [
    {
      "name": "Path",
      "args": {
        "pattern": "/DISCOVERY-SERVICE/**"
      }
    }
  ],
  "filters": [
    {
      "name": "RewritePath",
      "args": {
        "regexp": "/DISCOVERY-SERVICE/(?<remaining>.*)",
        "replacement": "/${remaining}"
      }
    }
  ],
  "uri": "lb://DISCOVERY-SERVICE",
  "order": 0
}

/actuator/gateway/routes/CompositeDiscoveryClient_DISCOVERY-SERVICE/combinedfilters

{
  "Route{id='CompositeDiscoveryClient_DISCOVERY-SERVICE', uri=lb://DISCOVERY-SERVICE, order=0, predicate=org.springframework.cloud.gateway.handler.predicate.PathRoutePredicateFactory$$Lambda$769/1774209584@7d9639ad, gatewayFilters=[OrderedGatewayFilter{delegate=org.springframework.cloud.gateway.filter.factory.RewritePathGatewayFilterFactory$$Lambda$771/1052389952@528c8627, order=1}]}": 0
}

Summary

Springcloud gateway provides a gateway actuator. The endpiont provides information query on filter and routes and rest api specifying update of route information, which provides great convenience for web interface to provide management configuration function.

doc