I couldn't seem to find a clear example/solution to the following scenario; any help/information would be appreciated!
I have a Spring REST API service that uses Spring Data JPA to interface to a backend database server. I am running this exact same service on multiple machines, and I have a reverse proxy that routes client requests (using Netflix Zuul) to these API services in order to access the data in the database. However, I want to load balance the requests (via the reverse proxy and possibly Netflix Ribbon) so that each request will only be sent to a single API server (in a load-balanced fashion).
Spring Data JPA automatically configures endpoints based on the entity classes and rest repositories I define. One solution would be to generate an equivalent endpoint on the reverse proxy for each and every endpoint on the API services, and then use a Ribbon client to load balance each endpoint individually. However, this does not seem like the appropriate solution.
My question is, does Netflix Zuul or Ribbon provide any functionality to handle this sort of scenario? Essentially, I would like to be able to set a YAML config that simply tells Zuul to use a Ribbon client and automatically load balance all requests to a given endpoint, according to the available listOfServers Ribbon config.
application.yml
Example:
DatabaseAPI:
ribbon:
eureka:
enabled: false
listOfServers: localhost:8080, localhost:8181, localhost:8282
ServerListRefreshInterval: 15000
zuul:
routes:
data:
path: /db/**
ServiceId: DatabaseAPI
Now, for example, I want each request to /db/** to be sent to one of the available servers in the server list, in a round-robin fashion. Note: With this example config, every request is sent to ALL the available servers simultaneously. I only want ONE of them to receive each request.
by default Zuul uses Ribbon to locate an instance to forward to via discovery (e.g Eureka in your case). So, in Gateway application (Zuul) you dont need to have Ribbon in the classpath.
in case you dont see the loadbalancing between your instances through Zuul, try multiplying requests (e.g > 200 request)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With