diff --git a/2.0.x/multi/multi_spring-cloud-consul-discovery.html b/2.0.x/multi/multi_spring-cloud-consul-discovery.html index 0230c0a8..6901e68f 100644 --- a/2.0.x/multi/multi_spring-cloud-consul-discovery.html +++ b/2.0.x/multi/multi_spring-cloud-consul-discovery.html @@ -38,7 +38,19 @@ consul: discovery: instanceId: ${spring.application.name}:${vcap.application.instance_id:${spring.application.instance_id:${random.value}}}
-
With this metadata, and multiple service instances deployed on localhost, the random value will kick in there to make the instance unique. In Cloudfoundry the vcap.application.instance_id will be populated automatically in a Spring Boot application, so the random value will not be needed.
Spring Cloud has support for Feign (a REST client builder) and also Spring RestTemplate using the logical service names instead of physical URLs.
You can also use the org.springframework.cloud.client.discovery.DiscoveryClient which provides a simple API for discovery clients that is not specific to Netflix, e.g.
@Autowired +With this metadata, and multiple service instances deployed on localhost, the random value will kick in there to make the instance unique. In Cloudfoundry the
vcap.application.instance_idwill be populated automatically in a Spring Boot application, so the random value will not be needed.
Spring Cloud has support for Feign (a REST client builder) and also Spring RestTemplate
+for looking up services using the logical service names/ids instead of physical URLs. Both Feign and the discovery-aware RestTemplate utilize Ribbon for client-side load balancing.
If you want to access service STORES using the RestTemplate simply declare:
@LoadBalanced
+@Bean
+public RestTemplate loadbalancedRestTemplate() {
+ new RestTemplate();
+}and use it like this (notice how we use the STORES service name/id from Consul instead of a fully qualified domainname):
@Autowired
+RestTemplate restTemplate;
+
+public String getFirstProduct() {
+ return this.restTemplate.getForObject("https://STORES/products/1", String.class);
+}If you have Consul clusters in multiple datacenters and you want to access a service in another datacenter a service name/id alone is not enough. In that case
+you use property spring.cloud.consul.discovery.datacenters.STORES=dc-west where STORES is the service name/id and dc-west is the datacenter
+where the STORES service lives.
You can also use the org.springframework.cloud.client.discovery.DiscoveryClient which provides a simple API for discovery clients that is not specific to Netflix, e.g.
@Autowired
private DiscoveryClient discoveryClient;
public String serviceUrl() {
@@ -47,4 +59,4 @@ public String serviceUrl() {
return list.get(0).getUri();
}
return null;
-}