[英]Zuul proxy to different URL according to logged in user
I'm designing some bot farm where each user has its own bot, and I would like to achieve the following 我正在设计一些机器人场,每个用户都有自己的机器人,我希望实现以下目标
So far I saw examples to redirect to specific service according to the path. 到目前为止,我已经看到了根据路径重定向到特定服务的示例。 but is it achievable to do this dynamically according to the logged in user's bot IP?
但是可以根据登录的用户的bot IP动态地执行此操作吗?
I was able to achieve it by writing the following filter: 我可以通过编写以下过滤器来实现:
@Override
public String filterType() {
return PRE_TYPE;
}
@Override
public int filterOrder() {
return PRE_DECORATION_FILTER_ORDER + 1;
}
public Object run() {
RequestContext ctx = getCurrentContext();
ctx.put(REQUEST_URI_KEY, "/test/");
try {
if (new Random().nextInt(10) > 5) {
ctx.setRouteHost(new URL("http://192.168.1.14:8088"));
} else {
ctx.setRouteHost(new URL("http://192.168.1.14:8089"));
}
} catch (MalformedURLException e) {
log.error("", e);
}
return null;
}
my application.properties looks like so: 我的application.properties看起来像这样:
spring.application.name=zuul-server
server.port=8080
management.endpoints.web.exposure.include=*
zuul.routes.test.path=/test/**
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.