我正在使用微服务架构构建 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