4
votes

According to this blog https://spring.io/blog/2015/07/14/microservices-with-spring which is based on eureka service discovery and where the service discovery is working properly.

But when have switched to use Consul instead Eureka the service discovery is not working and getting this error:

java.lang.IllegalStateException: No instances available for ACCOUNTS-SERVICE
at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:79)
at org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor.intercept(LoadBalancerInterceptor.java:46) ...

UPDATED: After have fixed the previous error by providing the correct health-check endpoint (see the answer below), when deploying the services to Cloud Foundry with properly provided host and port of the Consul server in bootstrap.yml (Consul based PropertySource loaded during the 'bootstrap' phase):

---
spring:
  profiles: cloud
  cloud:
    consul:
      host: <consul host or ip>
      port: 8500

Consul is registering the service, but with critical state (failing)!

Would appreciate any help or guidance.

Thanks

1
Did you checked the Consul UI if the service gets successfully registered? Just to eliminate if registration or discovery is you issue. - daniel.eichten
Yes the service is failing (marked as critical). - kmarabet
Did you maybe tweaked your health checks? - daniel.eichten
Yes thanks it was related to the "Consul" health check default path which is set to the /health endpoint, so after have enabled the spring-actuator the issue was resolved. - kmarabet
But when deploying the services to Cloud Foundry, Consul is registering them but with critical state (failing) having the /health endpoint! Any idea what could cause that? - kmarabet

1 Answers

3
votes

The issue was related to the Consul health check default path which is set to the /health endpoint. Thus after have enabled the spring-actuator in all clients applications (web-server and micro-service) this issue was resolved.

Or you may change the default Consul health-check endpoint in the bootstrap.yml file:

  cloud:
    consul:
      discovery:
        healthCheckPath: /test

NB. To enable spring-actuator in maven the following dependency was added to the pom.xml file:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

For more information see: http://cloud.spring.io/spring-cloud-consul/spring-cloud-consul.html

When deploying (pushing) to CF (CloudFoundry) the URI of the deployed application should be provided to Consul for service discovery process (CF provides application's URIs in vcap.application.uris environment variable), thus the following configuration should be added to the bootsrap.yml file:

---
spring:
  profiles: cloud
  cloud:
    consul:
      host: <consul host or ip>
      port: 8500
      discovery:
        instanceId: ${spring.application.name}:${vcap.application.application_name}:${vcap.application.instance_id}
        hostname: ${vcap.application.uris[0]}
        port: 80

NB. instanceId is used by Consul to register the application (microservice) instance.