如何实现基于请求params的变更servciceId?
下面是我们的Zuul Config
zuul:
host:
connect-timeout-millis: 200000
connection-request-timeout-millis: 200000
socket-timeout-millis: 200000
ignored-services: "*"
routes:
route-1:
path: /path1/**
serviceId: ServiceA
route-2:
path: /path2/**
serviceId: ServiceB在这里,我们根据路径1/路径2选择serviceId。
如果是http://localhost:8050/path1/endpointPath?requestParam=ParamValue1,这应该调用serviceA
如果是http://localhost:8050/path1/endpointPath?requestParam=ParamValue2,这应该调用serviceB
发布于 2019-09-19 13:51:45
能够通过使用路由筛选器和配置更改来实现这一点。
配置:
routes:
route-1:
path: /**
serviceId: ServiceA
stripPrefix: trueRouteFilter:
Optional<String> parameter = Optional.ofNullable(ctx.getRequest().getParameter("requestparam"));
if (parameter.isPresent()) {
if (parameter.get().equalsIgnoreCase("ValueA")) {
ctx.set("serviceId", "ServiceA");
} else {
ctx.set("serviceId", "ServiceB");
}
}这是好的,还是我们有更简单的方法来实现?在这里,我们可以限制在属性文件中不定义serviceId吗?
https://stackoverflow.com/questions/58006343
复制相似问题