kmarabet
kmarabet

Reputation: 1117

Consul service discovery issue with spring boot applications

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

Upvotes: 4

Views: 10372

Answers (1)

kmarabet
kmarabet

Reputation: 1117

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.

Upvotes: 4

Related Questions