Search code examples
microservicesnetflix-eureka

Custom service discovery using Neflix Eureka


Currently, I am working on a POC in my organization. Our goal is to implement Service Discovery. For that reason, I was exploring Eureka. Eureka is pretty great for service discovery without any conditions. Our requirement is to implement conditional service discovery.

Our current implementation: Consumers consuming micro-service

This is a straight-forward implementation where we have multiple clients consuming services exposed by a single micro-service Service-A.

As we are planning to introduce a new micro-service Service-B with the same contract as Service-A. With this new service, clients will have to implement logic to identify which service to call based on some parameters. Each client will have to implement this logic: Multiple service providers

This is where Service Discovery comes in. I was trying out Eureka, but I couldn't find any document or resource which indicated that we can have custom logic for service registry or service discovery. I am not even sure if what I want to do is possible with Eureka. This is our goal: Custom service discovery in Eureka

We want to use Service discovery as we might add few more such services based on new types. What I tried was to have my own RestController which will then call internal methods of ApplicationResource. That did not work. I couldn't find any interface/abstract class that I can implement/extend to change the logic.

*Pardon my bad drawing skills.


Solution

  • Try using Netflix Zuul. This will also register with Eureka server and automatically set up dynamic routing based on other services that are registered with Eureka to provide access to our APIs through one singular point.

    I hope this link helps you: https://stackabuse.com/spring-cloud-routing-with-zuul-and-gateway/