我正在尝试禁用在运行时向 Eureka 注册的微服务的 Zuul 路由(我正在使用 Spring Boot)。
这是一个例子:
localhost/hello
localhost/world
这两个是注册的微服务。我想在运行时禁用到其中之一的路由而不将其关闭。
有没有办法做到这一点?
谢谢你,
Nano
除了使用 Cloud Config 之外,还可以自定义ZuulFilter https://netflix.github.io/zuul/javadoc/zuul-core/com/netflix/zuul/ZuulFilter.html可以使用。类似的东西(展示概念的部分实现):
public class BlackListFilter extends ZuulFilter {
@Override
public String filterType() {
return "pre";
}
...
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
String uri = ctx.getRequest().getRequestURI();
String appId = uri.split("/")[1];
if (blackList.contains(appId)) {
ctx.setSendZuulResponse(false);
LOG.info("Request '{}' from {}:{} is blocked",
uri, ctx.getRequest().getRemoteHost(), ctx.getRequest().getRemotePort());
}
return null;
}
}
where blackList
包含通过某些 RESTful API 等管理的应用程序 ID(Spring Boot 应用程序名称)列表。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)