首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何根据请求参数在运行时修改Zuul ServiceId?

如何根据请求参数在运行时修改Zuul ServiceId?
EN

Stack Overflow用户
提问于 2019-09-19 07:58:03
回答 1查看 79关注 0票数 0

如何实现基于请求params的变更servciceId?

下面是我们的Zuul Config

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

发布于 2019-09-19 13:51:45

能够通过使用路由筛选器和配置更改来实现这一点。

配置:

代码语言:javascript
复制
 routes:
    route-1:
      path: /**
      serviceId: ServiceA
      stripPrefix: true

RouteFilter:

代码语言:javascript
复制
 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吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58006343

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档