Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zuul url mapping with spring boot,Eureka

I am building Rest api using microservice architecture. I have multiple apis for user that we have made into multiple projects. I have everything else ready except I am not able to map the user facing url to the application url in zuul.

The user facing url is : user/v1/accountholders/{id}/cards and the actual url for my application is /user-cards/v1/accountholders/{id}/cards.

Here id is the path variable. Below are other similar api url so if there is a way to configure them generically in zuul. Also the context root of the application url is also the project name in 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}

Need some help to set this up in the properties or yml file for zuul. I havent been able to make any progress with the mapping stuff yet. Any inputs will be helpful.

SOLVED:- After getting the input from @Daniel (which is the accepted answer)This is what i used in 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
like image 214
Grinish Nepal Avatar asked Dec 15 '15 23:12

Grinish Nepal


People also ask

Does Zuul use Eureka?

Internally, Zuul uses Netflix Ribbon to look up for all instances of the service from the service discovery (Eureka Server).

How do Zuul and Eureka work together?

Zuul acts as the API gateway, providing a uniform, single point of entry into the set of microservices, while Eureka is essentially used as a “meta data” transport. Each client application instance (read microservice) registers its instance information (location, port, etc.) with the Eureka server.

Can Zuul work without Eureka?

GitHub - rishabhverma17/microservice-zuul-without-eureka: This service can be used to create microservice architecture with Gateway/Reverse Proxy using Zuul without using Eureka. This service can be used to create microservice architecture with Gateway/Reverse Proxy using Zuul without using Eureka.

What is the difference between Zuul and Eureka?

Eureka belongs to "Open Source Service Discovery" category of the tech stack, while Zuul can be primarily classified under "Microservices Tools". Eureka is an open source tool with 8.16K GitHub stars and 2.27K GitHub forks.


1 Answers

It is possible to achieve what you are trying to do by giving the correct Zuul config. Lets assume you have the user-cardholder service running on port 8081 and the user-account service on 8082 so that you can successfully answer requests going against:

http://localhost:8081/user-cardholder/accountholders/{id} 
http://localhost:8082/user-account/accountholders/{id}/accounts/{accid}

If this is working then you can achive what you are trying for these two services by using the following zuul config:

zuul:
  routes:
    cardholder:
      path: /user/accountholders/*
      url: http://localhost:8081/user-cardholder/accountholders/
    account:
      path: /user/accountholders/*/accounts/**
      url: http://localhost:8082/user-accounts/accountholders/

Unfortunately you will also have to add more configs – even when they go against the same backend service – due to the fact that internal and external urls are differing. Otherwise you could just add the option stripPrefix: false and use the same internally as externally.

like image 156
daniel.eichten Avatar answered Sep 24 '22 14:09

daniel.eichten