From fe56d96295b18192c358e0822cc529778f632fee Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Thu, 27 Oct 2016 14:25:18 -0400 Subject: [PATCH 1/3] Fixes #1429 --- .../main/asciidoc/spring-cloud-netflix.adoc | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/docs/src/main/asciidoc/spring-cloud-netflix.adoc b/docs/src/main/asciidoc/spring-cloud-netflix.adoc index 65052fe6..91d97543 100644 --- a/docs/src/main/asciidoc/spring-cloud-netflix.adoc +++ b/docs/src/main/asciidoc/spring-cloud-netflix.adoc @@ -1236,7 +1236,8 @@ To enable it, annotate a Spring Boot main class with service. By convention, a service with the ID "users", will receive requests from the proxy located at `/users` (with the prefix stripped). The proxy uses Ribbon to locate an instance to forward to -via discovery, and all requests are executed in a hystrix command, so +via discovery, and all requests are executed in a +<>, so failures will show up in Hystrix metrics, and once the circuit is open the proxy will not try to contact the service. @@ -1604,6 +1605,61 @@ possible filters that are enabled. If you want to disable one, simply set `org.springframework.cloud.netflix.zuul.filters.post.SendResponseFilter` set `zuul.SendResponseFilter.post.disable=true`. +[[hystrix-fallbacks-for-routes]] +=== Providing Hystrix Fallbacks For Routes + +When a circuit for a given route in Zuul is tripped you can provide a fallback response +by creating a bean of type `ZuulFallbackProvider`. Within this bean you need to specify +the route ID the fallback is for and provide a `ClientHttpResponse` to return +as a fallback. Here is a very simple `ZuulFallbackProvider` implementation. + +[source,java] +---- +class MyFallbackProvider implements ZuulFallbackProvider { + @Override + public String getRoute() { + return "zuulserver"; + } + + @Override + public ClientHttpResponse fallbackResponse() { + return new ClientHttpResponse() { + @Override + public HttpStatus getStatusCode() throws IOException { + return HttpStatus.OK; + } + + @Override + public int getRawStatusCode() throws IOException { + return 200; + } + + @Override + public String getStatusText() throws IOException { + return "OK"; + } + + @Override + public void close() { + + } + + @Override + public InputStream getBody() throws IOException { + return new ByteArrayInputStream("fallback".getBytes()); + } + + @Override + public HttpHeaders getHeaders() { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.TEXT_HTML); + return headers; + } + }; + } +} +---- + === Polyglot support with Sidecar Do you have non-jvm languages you want to take advantage of Eureka, Ribbon and From 8a7df36d883b535c87b71ebfb158d1726384b8c1 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Thu, 27 Oct 2016 15:02:17 -0400 Subject: [PATCH 2/3] Added route config --- docs/src/main/asciidoc/spring-cloud-netflix.adoc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/src/main/asciidoc/spring-cloud-netflix.adoc b/docs/src/main/asciidoc/spring-cloud-netflix.adoc index 91d97543..ad1d9458 100644 --- a/docs/src/main/asciidoc/spring-cloud-netflix.adoc +++ b/docs/src/main/asciidoc/spring-cloud-netflix.adoc @@ -1618,7 +1618,7 @@ as a fallback. Here is a very simple `ZuulFallbackProvider` implementation. class MyFallbackProvider implements ZuulFallbackProvider { @Override public String getRoute() { - return "zuulserver"; + return "customers"; } @Override @@ -1660,6 +1660,15 @@ class MyFallbackProvider implements ZuulFallbackProvider { } ---- +And here is what the route configuration would look like. + +[source,yaml] +---- +zuul: + routes: + customers: /customers/** +---- + === Polyglot support with Sidecar Do you have non-jvm languages you want to take advantage of Eureka, Ribbon and From 14a31cd5f8521c99e1a79308ae51f8580dcdb1a7 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Thu, 27 Oct 2016 15:09:21 -0400 Subject: [PATCH 3/3] Switched media type to application/json --- docs/src/main/asciidoc/spring-cloud-netflix.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/main/asciidoc/spring-cloud-netflix.adoc b/docs/src/main/asciidoc/spring-cloud-netflix.adoc index ad1d9458..129b47dd 100644 --- a/docs/src/main/asciidoc/spring-cloud-netflix.adoc +++ b/docs/src/main/asciidoc/spring-cloud-netflix.adoc @@ -1652,7 +1652,7 @@ class MyFallbackProvider implements ZuulFallbackProvider { @Override public HttpHeaders getHeaders() { HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.TEXT_HTML); + headers.setContentType(MediaType.APPLICATION_JSON); return headers; } };