Search code examples
javamicroservicesnetflix-ribbon

Failure while calling a microservice via ribbon enabled client(Without eureka service discovery)


I am trying to call a 'microservice'(microservice-producer) via ribbon enabled the client(ribbon-client) but it is giving me an error.

java.lang.IllegalStateException: No instances available for employee-microservice

I am following the official spring.io link for the client side load balancing(https://spring.io/guides/gs/client-side-load-balancing/) and I am also following all the specification given at this link. You can see the code at my GitHub address : (https://github.com/vickygupta0017/microservice-ribbon).

I am not sure what I am missing or doing wrong, could someone please help me out?


Solution

  • In case where eureka server is not used to identify whether server is reachable or not , ribbon client uses "RibbonConfiguration" - pingUrl parameter. By Default it is empty string that means it is going to ping list of server without any context to get an answer whether server is reachable or not. So here you can do 2 things.

    1. Create a service that is bound to root context of the server "/" and send a positive response.

      @RequestMapping(value = "/")
      public String status(HttpServletRequest request) {
          return "";
      }
      
    2. Or update Ribbon client Configuration (EmployeeConfiguration) and return PingUrl with relevant "service-name".

      @Bean
      public IPing ribbonPing(IClientConfig config) {
         return new PingUrl(false,"/employees");
      }
      

    Go for the first one as it will solve the basic purpose to see if server is reachable or not.

    Ref: https://spring.io/guides/gs/client-side-load-balancing/

    Our IPing is a PingUrl, which will ping a URL to check the status of each server. Say Hello has, as you’ll recall, a method mapped to the / path; that means that Ribbon will get an HTTP 200 response when it pings a running Say Hello server. The IRule we set up, the AvailabilityFilteringRule, will use Ribbon’s built-in circuit breaker functionality to filter out any servers in an “open-circuit” state: if a ping fails to connect to a given server, or if it gets a read failure for the server, Ribbon will consider that server “dead” until it begins to respond normally.