1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| public class MyFallbackProvider implements ZuulFallbackProvider { @Override public String getRoute() { return "users-service"; //该值为注册中心的服务名 }
@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("<h1>fallback </h1>".getBytes()); }
@Override public HttpHeaders getHeaders() { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.APPLICATION_JSON); return httpHeaders; } }; } }
|