【问题标题】:How to proxy request in Jhipster Gateway?如何在 Jhipster 网关中代理请求?
【发布时间】:2019-05-31 21:04:36
【问题描述】:

我使用https://start.jhipster.tech/#/

创建了几个微服务和一个jhipster-gateway

在网关中,来自微服务的所有 API 都可用,但我需要在请求前缀中传递微服务名称。例如

http://localhost:8080/user-service/api/user
http://localhost:8080/pet-service/api/pets

代替这个,我想配置它,这样我就不需要在路径 url 中传递服务名称,如下所示

http://localhost:8080/api/user
http://localhost:8080/api/pets

我已尝试使用zuul 配置修复它,如下所示

zuul: 
    sensitive-headers: Cookie,Set-Cookie
    host:
        max-total-connections: 1000
        max-per-route-connections: 100
    semaphore:
        max-semaphores: 500
    routes:
        pets:
            path: /api/pets/**
            serviceId: pet-service
            stripPrefix: true
        users:
            path: /api/user/**
            serviceId: user-service
            stripPrefix: true

我从创始成员那里关注了这个演示。 https://www.youtube.com/watch?v=FuG5t_UW7pw

PS:我是 Jhipster 的新手,正在为我的下一个项目评估它。非常感谢任何帮助。

【问题讨论】:

  • 这并不像在yaml中配置路由那么简单,您需要修改代码以支持swagger url重写,访问控制过滤器,路由定位器等。代码不是很复杂但您需要以某种方式配置它。顺便说一句,你的标题是错误的,它是关于代理请求而不是重定向它们。
  • 视频长2h41m,非常感谢! (我喜欢带有法语(任何类型)口音xD的英语)看到/找到了这个(搜索'jhispter + zuul'):jhipster.tech/traefik? (但抱歉,不适合回答/您的 50 代表。))

标签: java spring jhipster netflix-zuul


【解决方案1】:

我认为你应该在zuul中设置前缀并设置路径映射。按照下面的例子:

zuul.prefix=/api //define a path for the gateway
zuul.ignored-services=* //ignore services that mustn't exposed
zuul.routes.userService.path=/users/** //map of service
zuul.routes.userService.serviceId=user-service
zuul.routes.userService.path=/pets/**
zuul.routes.petService.serviceId=pet-service

抱歉在属性中而不是在 yaml 中发布我的答案。

【讨论】:

    猜你喜欢
    • 2019-06-07
    • 1970-01-01
    • 2017-04-23
    • 1970-01-01
    • 2020-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-22
    相关资源
    最近更新 更多