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.

3.4 Using the DiscoveryClient

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_id will be populated automatically in a Spring Boot application, so the random value will not be needed.

3.4 Looking up services

3.4.1 Using Ribbon

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.

3.4.2 Using the DiscoveryClient

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;
-}
\ No newline at end of file +} \ No newline at end of file diff --git a/2.0.x/multi/multi_spring-cloud-consul.html b/2.0.x/multi/multi_spring-cloud-consul.html index d4f65e51..89684001 100644 --- a/2.0.x/multi/multi_spring-cloud-consul.html +++ b/2.0.x/multi/multi_spring-cloud-consul.html @@ -1,3 +1,3 @@ - Spring Cloud Consul

Spring Cloud Consul


Table of Contents

1. Install Consul
2. Consul Agent
3. Service Discovery with Consul
3.1. How to activate
3.2. Registering with Consul
3.3. HTTP Health Check
3.3.1. Metadata and Consul tags
3.3.2. Making the Consul Instance ID Unique
3.4. Using the DiscoveryClient
4. Distributed Configuration with Consul
4.1. How to activate
4.2. Customizing
4.3. Config Watch
4.4. YAML or Properties with Config
4.5. git2consul with Config
4.6. Fail Fast
5. Consul Retry
6. Spring Cloud Bus with Consul
6.1. How to activate
7. Circuit Breaker with Hystrix
8. Hystrix metrics aggregation with Turbine and Consul
\ No newline at end of file + Spring Cloud Consul

Spring Cloud Consul


Table of Contents

1. Install Consul
2. Consul Agent
3. Service Discovery with Consul
3.1. How to activate
3.2. Registering with Consul
3.3. HTTP Health Check
3.3.1. Metadata and Consul tags
3.3.2. Making the Consul Instance ID Unique
3.4. Looking up services
3.4.1. Using Ribbon
3.4.2. Using the DiscoveryClient
4. Distributed Configuration with Consul
4.1. How to activate
4.2. Customizing
4.3. Config Watch
4.4. YAML or Properties with Config
4.5. git2consul with Config
4.6. Fail Fast
5. Consul Retry
6. Spring Cloud Bus with Consul
6.1. How to activate
7. Circuit Breaker with Hystrix
8. Hystrix metrics aggregation with Turbine and Consul
\ No newline at end of file diff --git a/2.0.x/single/spring-cloud-consul.html b/2.0.x/single/spring-cloud-consul.html index 05df71f6..9651074a 100644 --- a/2.0.x/single/spring-cloud-consul.html +++ b/2.0.x/single/spring-cloud-consul.html @@ -1,6 +1,6 @@ - Spring Cloud Consul

Spring Cloud Consul


Table of Contents

1. Install Consul
2. Consul Agent
3. Service Discovery with Consul
3.1. How to activate
3.2. Registering with Consul
3.3. HTTP Health Check
3.3.1. Metadata and Consul tags
3.3.2. Making the Consul Instance ID Unique
3.4. Using the DiscoveryClient
4. Distributed Configuration with Consul
4.1. How to activate
4.2. Customizing
4.3. Config Watch
4.4. YAML or Properties with Config
4.5. git2consul with Config
4.6. Fail Fast
5. Consul Retry
6. Spring Cloud Bus with Consul
6.1. How to activate
7. Circuit Breaker with Hystrix
8. Hystrix metrics aggregation with Turbine and Consul

2.0.0.BUILD-SNAPSHOT

This project provides Consul integrations for Spring Boot apps through autoconfiguration + Spring Cloud Consul

Spring Cloud Consul


2.0.0.BUILD-SNAPSHOT

This project provides Consul integrations for Spring Boot apps through autoconfiguration and binding to the Spring Environment and other Spring programming model idioms. With a few simple annotations you can quickly enable and configure the common patterns inside your application and build large distributed systems with Consul based components. The @@ -44,7 +44,19 @@ Intelligent Routing (Zuul) and Client Side Load Balancing (Ribbon), Circuit Brea 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.

3.4 Using the DiscoveryClient

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_id will be populated automatically in a Spring Boot application, so the random value will not be needed.

3.4 Looking up services

3.4.1 Using Ribbon

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.

3.4.2 Using the DiscoveryClient

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() {
@@ -53,7 +65,7 @@ public String serviceUrl() {
         return list.get(0).getUri();
     }
     return null;
-}

4. Distributed Configuration with Consul

Consul provides a Key/Value Store for storing configuration and other metadata. Spring Cloud Consul Config is an alternative to the Config Server and Client. Configuration is loaded into the Spring Environment during the special "bootstrap" phase. Configuration is stored in the /config folder by default. Multiple PropertySource instances are created based on the application’s name and the active profiles that mimicks the Spring Cloud Config order of resolving properties. For example, an application with the name "testApp" and with the "dev" profile will have the following property sources created:

config/testApp,dev/
+}

4. Distributed Configuration with Consul

Consul provides a Key/Value Store for storing configuration and other metadata. Spring Cloud Consul Config is an alternative to the Config Server and Client. Configuration is loaded into the Spring Environment during the special "bootstrap" phase. Configuration is stored in the /config folder by default. Multiple PropertySource instances are created based on the application’s name and the active profiles that mimicks the Spring Cloud Config order of resolving properties. For example, an application with the name "testApp" and with the "dev" profile will have the following property sources created:

config/testApp,dev/
 config/testApp/
 config/application,dev/
 config/application/

The most specific property source is at the top, with the least specific at the bottom. Properties in the config/application folder are applicable to all applications using consul for configuration. Properties in the config/testApp folder are only available to the instances of the service named "testApp".

Configuration is currently read on startup of the application. Sending a HTTP POST to /refresh will cause the configuration to be reloaded. Section 4.3, “Config Watch” will also automatically detect changes and reload the application context.

4.1 How to activate

To get started with Consul Configuration use the starter with group org.springframework.cloud and artifact id spring-cloud-starter-consul-config. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.

This will enable auto-configuration that will setup Spring Cloud Consul Config.

4.2 Customizing

Consul Config may be customized using the following properties:

bootstrap.yml.  diff --git a/2.0.x/spring-cloud-consul.xml b/2.0.x/spring-cloud-consul.xml index 17e5d892..8894596e 100644 --- a/2.0.x/spring-cloud-consul.xml +++ b/2.0.x/spring-cloud-consul.xml @@ -4,7 +4,7 @@ Spring Cloud Consul -2017-10-23 +2017-10-24 @@ -115,9 +115,31 @@ public class Application { 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. +

+Looking up services +
+Using Ribbon +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. +
Using the DiscoveryClient -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 private DiscoveryClient discoveryClient; @@ -130,6 +152,7 @@ public String serviceUrl() { return null; }
+
Distributed Configuration with Consul