如何在Jhipster网关中代理请求?

时间:2019-01-05 15:23:35

标签: java spring jhipster netflix-zuul

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

创建了几个微服务和一个 jhipster网关

在网关中,所有微服务的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的新手,正在为我的下一个项目进行评估。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分: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中发布我的答案的信息。