From b39068669c19a8c6194dae509e36759560cbeebe Mon Sep 17 00:00:00 2001 From: buildmaster Date: Thu, 16 Nov 2017 17:24:27 +0000 Subject: [PATCH] Sync docs from 2.0.x to gh-pages --- 2.0.x/multi/multi__configuration.html | 16 +++++++++++----- 2.0.x/single/spring-cloud-gateway.html | 16 +++++++++++----- 2.0.x/spring-cloud-gateway.xml | 16 +++++++++++----- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/2.0.x/multi/multi__configuration.html b/2.0.x/multi/multi__configuration.html index 1ffb52ce..5fcc749c 100644 --- a/2.0.x/multi/multi__configuration.html +++ b/2.0.x/multi/multi__configuration.html @@ -20,21 +20,27 @@ uri: http://example.org filters: - SetStatus=401

-

For some usages of the gateway, properties will be adequate, but some production use cases will benefit from loading configuration from an external source, such as a database. Future milestone versions will have RouteDefinitionLocator implementations based off of Spring Data Repositories such as: Redis, MongoDB and Cassandra.

7.1 Fluent Java Routes API

To allow for simple configuration in Java, there is a fluent API defined in the Routes class.

Config.java.  +

For some usages of the gateway, properties will be adequate, but some production use cases will benefit from loading configuration from an external source, such as a database. Future milestone versions will have RouteDefinitionLocator implementations based off of Spring Data Repositories such as: Redis, MongoDB and Cassandra.

7.1 Fluent Java Routes API

To allow for simple configuration in Java, there is a fluent API defined in the Routes class.

GatewaySampleApplication.java. 

// static imports from GatewayFilters and RoutePredicates
 @Bean
 public RouteLocator customRouteLocator(ThrottleGatewayFilterFactory throttle) {
     return Routes.locator()
             .route("test")
-                .uri("http://httpbin.org:80")
                 .predicate(host("**.abc.org").and(path("/image/png")))
                 .addResponseHeader("X-TestHeader", "foobar")
-                .and()
-            .route("test2")
                 .uri("http://httpbin.org:80")
+            .route("test2")
                 .predicate(path("/image/webp"))
                 .add(addResponseHeader("X-AnotherHeader", "baz"))
-                .and()
+                .uri("http://httpbin.org:80")
+            .route("test3")
+                .order(-1)
+                .predicate(host("**.throttle.org").and(path("/get")))
+                .add(throttle.apply(tuple().of("capacity", 1,
+                     "refillTokens", 1,
+                     "refillPeriod", 10,
+                     "refillUnit", "SECONDS")))
+                .uri("http://httpbin.org:80")
             .build();
 }

This style also allows for more custom predicate assertions. The predicates defined by RouteDefinitionLocator beans are combined using logical and. By using the fluent Java API, you can use the and(), or() and negate() operators on the Predicate class.

\ No newline at end of file diff --git a/2.0.x/single/spring-cloud-gateway.html b/2.0.x/single/spring-cloud-gateway.html index 9d6f45b3..a5048249 100644 --- a/2.0.x/single/spring-cloud-gateway.html +++ b/2.0.x/single/spring-cloud-gateway.html @@ -278,21 +278,27 @@ KeyResolver userKeyResolver() { uri: http://example.org filters: - SetStatus=401

-

For some usages of the gateway, properties will be adequate, but some production use cases will benefit from loading configuration from an external source, such as a database. Future milestone versions will have RouteDefinitionLocator implementations based off of Spring Data Repositories such as: Redis, MongoDB and Cassandra.

7.1 Fluent Java Routes API

To allow for simple configuration in Java, there is a fluent API defined in the Routes class.

Config.java.  +

For some usages of the gateway, properties will be adequate, but some production use cases will benefit from loading configuration from an external source, such as a database. Future milestone versions will have RouteDefinitionLocator implementations based off of Spring Data Repositories such as: Redis, MongoDB and Cassandra.

7.1 Fluent Java Routes API

To allow for simple configuration in Java, there is a fluent API defined in the Routes class.

GatewaySampleApplication.java. 

// static imports from GatewayFilters and RoutePredicates
 @Bean
 public RouteLocator customRouteLocator(ThrottleGatewayFilterFactory throttle) {
     return Routes.locator()
             .route("test")
-                .uri("http://httpbin.org:80")
                 .predicate(host("**.abc.org").and(path("/image/png")))
                 .addResponseHeader("X-TestHeader", "foobar")
-                .and()
-            .route("test2")
                 .uri("http://httpbin.org:80")
+            .route("test2")
                 .predicate(path("/image/webp"))
                 .add(addResponseHeader("X-AnotherHeader", "baz"))
-                .and()
+                .uri("http://httpbin.org:80")
+            .route("test3")
+                .order(-1)
+                .predicate(host("**.throttle.org").and(path("/get")))
+                .add(throttle.apply(tuple().of("capacity", 1,
+                     "refillTokens", 1,
+                     "refillPeriod", 10,
+                     "refillUnit", "SECONDS")))
+                .uri("http://httpbin.org:80")
             .build();
 }

This style also allows for more custom predicate assertions. The predicates defined by RouteDefinitionLocator beans are combined using logical and. By using the fluent Java API, you can use the and(), or() and negate() operators on the Predicate class.

8. Actuator API

TODO: document the /gateway actuator endpoint

9. Developer Guide

TODO: overview of writing custom integrations

9.1 Writing Custom Route Predicate Factories

TODO: document writing Custom Route Predicate Factories

9.2 Writing Custom GatewayFilter Factories

TODO: document writing Custom GatewayFilter Factories

9.3 Writing Custom Global Filters

TODO: document writing Custom Global Filters

9.4 Writing Custom Route Locators and Writers

TODO: document writing Custom Route Locators and Writers

10. Building a Simple Gateway Using Spring MVC

Spring Cloud Gateway provides a utility object called ProxyExchange which you can use inside a regular Spring MVC handler as a method parameter. It supports basic downstream HTTP exchanges via methods that mirror the HTTP verbs, or forwarding to a local handler via the forward() method.

Example (proxying a request to "/test" downstream to a remote server):

@RestController
diff --git a/2.0.x/spring-cloud-gateway.xml b/2.0.x/spring-cloud-gateway.xml
index 6790f930..8933c0ec 100644
--- a/2.0.x/spring-cloud-gateway.xml
+++ b/2.0.x/spring-cloud-gateway.xml
@@ -695,22 +695,28 @@ KeyResolver userKeyResolver() {
 Fluent Java Routes API
 To allow for simple configuration in Java, there is a fluent API defined in the Routes class.
 
-Config.java
+GatewaySampleApplication.java
 
 // static imports from GatewayFilters and RoutePredicates
 @Bean
 public RouteLocator customRouteLocator(ThrottleGatewayFilterFactory throttle) {
     return Routes.locator()
             .route("test")
-                .uri("http://httpbin.org:80")
                 .predicate(host("**.abc.org").and(path("/image/png")))
                 .addResponseHeader("X-TestHeader", "foobar")
-                .and()
-            .route("test2")
                 .uri("http://httpbin.org:80")
+            .route("test2")
                 .predicate(path("/image/webp"))
                 .add(addResponseHeader("X-AnotherHeader", "baz"))
-                .and()
+                .uri("http://httpbin.org:80")
+            .route("test3")
+                .order(-1)
+                .predicate(host("**.throttle.org").and(path("/get")))
+                .add(throttle.apply(tuple().of("capacity", 1,
+                     "refillTokens", 1,
+                     "refillPeriod", 10,
+                     "refillUnit", "SECONDS")))
+                .uri("http://httpbin.org:80")
             .build();
 }