容错与回退
复制zuul项目,修改ArtifactId 如zuul-falllback
写Zuul的回退类
@Component
public class ZuulFallBackProvider implements ZuulFallBackProvider{
@override
public String getRoute(){
return "service-name"; //为哪个服务提供回退
}
@Override
public ClientHttpResponse fallbackResponse(){
return new ClientHttpResponse(){
@Override
public HttpStatus getStatusCode(){
return HttpStatus.OK;
}
……
@Override
public InputStream getBody(){
return new ByteArrayInputStream("该服务暂不可用!".getBytes());
}
}
}
}
Zuul的高可用分为两种场景
(1)Zuul注册到了Eureka Server上
将多个Zuul节点注册到Eureka Server上,就可以实现Zuul的高可用。此时,Zuul的高可用与其他微服务的高可用没区别
(2)Zuul未注册到Eureka Server上