【发布时间】:2016-03-21 23:23:59
【问题描述】:
我正在使用微服务架构构建 Rest api。我有多个我们已经制作成多个项目的用户 api。除了我无法将面向用户的 url 映射到 zuul 中的应用程序 url 之外,我已经准备好了其他所有东西。
面向用户的 url 是:user/v1/accountholders/{id}/cards,而我的应用程序的实际 url 是 /user-cards/v1/accountholders/{id}/cards。
这里的 id 是路径变量。下面是其他类似的 api url,所以如果有一种方法可以在 zuul 中通用地配置它们。应用程序url的上下文根也是Eureka中的项目名称。
Other similar urls are:
client side:- /user/v1/accountholders/{id}/cards/{cardid}
application:- /user-cards/v1/accountholders/{id}/cards/{cardid}
client side:- /user/v1/accountholders
application:- /user-cardholder/v1/accountholder
client side:- /user/v1/accountholders
application:- /user-cardholder/v1/accountholder
client side:- /user/v1/accountholders/{id}
application:- /user-cardholder/v1/accountholders/{id}
client side:- /user/v1/accountholders/{id}/accounts
application:- /user-accounts/v1/accountholders/{id}/accounts
client side:- /user/v1/accountholders/{id}/accounts/{accid}
application:- /user-accounts/v1/accountholders/{id}/accounts/{accid}
需要一些帮助才能在 zuul 的属性或 yml 文件中进行设置。我还没有在映射方面取得任何进展。任何输入都会有所帮助。
已解决:- 从@Daniel 获得输入后(这是公认的答案)这是我在 zuul config 中使用的:-
zuul:
routes:
User-Cards:
path: /user/v1/accountholders/*/cards/**
url: http://desktop-uvkv1ed:9999/user-cards/v1/accountholders
User-Transactions1:
path: /user/v1/accountholders/*/transactions
url: http://desktop-uvkv1ed:5555/user-transactions/v1/accountholders
service-id: User-Transactions
User-Transactions2:
path: /user/v1/accountholders/*/accounts/*/transactions
url: http://desktop-uvkv1ed:5555/user-transactions/v1/accountholders
service-id: User-Transactions
User-Accounts:
path: /user/v1/accountholders/*/accounts/**
url: http://desktop-uvkv1ed:7777/user-accounts/v1/accountholders
User-Cardholders:
path: /user/v1/accountholders/**
url: http://desktop-uvkv1ed:8888/user-cardholders/v1/accountholders
【问题讨论】:
-
乍一看,我不认为你想要的目前是可能的,但支持正则表达式映射的拉取请求应该很快就会出现。 github.com/spring-cloud/spring-cloud-netflix/pull/699
-
你能帮助我使用我可以使用的方法吗?我可以使用应用程序 url,但不能使用面向用户的 url,以便我可以轻松地执行映射。
-
@spencergibb 实际上这可能是因为本质上都可以追溯到
AbstractUrlMappingHandler的子类,它确实支持蚂蚁风格的模式匹配。
标签: spring-boot spring-cloud microservices netflix-eureka netflix-zuul