diff --git a/multi/multi_pr01.html b/multi/multi_pr01.html index 9e3592da..41fa626c 100644 --- a/multi/multi_pr01.html +++ b/multi/multi_pr01.html @@ -1,6 +1,6 @@ -

1.2.2.BUILD-SNAPSHOT

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

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 diff --git a/multi/multi_spring-cloud-consul-config.html b/multi/multi_spring-cloud-consul-config.html index 8c6132e8..ee143324 100644 --- a/multi/multi_spring-cloud-consul-config.html +++ b/multi/multi_spring-cloud-consul-config.html @@ -3,7 +3,7 @@ 4. Distributed Configuration with Consul

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. Watching the key value store (which Consul supports) is not currently possible, but will be a future addition to this project.

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.  +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. 

spring:
   cloud:
     consul:
diff --git a/multi/multi_spring-cloud-consul-discovery.html b/multi/multi_spring-cloud-consul-discovery.html
index 80cdf1e6..6901e68f 100644
--- a/multi/multi_spring-cloud-consul-discovery.html
+++ b/multi/multi_spring-cloud-consul-discovery.html
@@ -19,7 +19,7 @@
     consul:
       host: localhost
       port: 8500

-

[Caution]Caution

If you use Spring Cloud Consul Config, the above values will need to be placed in bootstrap.yml instead of application.yml.

The default service name, instance id and port, taken from the Environment, are ${spring.application.name}, the Spring Context ID and ${server.port} respectively.

To disable the Consul Discovery Client you can set spring.cloud.consul.discovery.enabled to false.

3.3 HTTP Health Check

The health check for a Consul instance defaults to "/health", which is the default locations of a useful endpoint in a Spring Boot Actuator application. You need to change these, even for an Actuator application if you use a non-default context path or servlet path (e.g. server.servletPath=/foo) or management endpoint path (e.g. management.context-path=/admin). The interval that Consul uses to check the health endpoint may also be configured. "10s" and "1m" represent 10 seconds and 1 minute respectively. Example:

application.yml.  +

[Caution]Caution

If you use Spring Cloud Consul Config, the above values will need to be placed in bootstrap.yml instead of application.yml.

The default service name, instance id and port, taken from the Environment, are ${spring.application.name}, the Spring Context ID and ${server.port} respectively.

To disable the Consul Discovery Client you can set spring.cloud.consul.discovery.enabled to false.

To disable the service registration you can set spring.cloud.consul.discovery.register to false.

3.3 HTTP Health Check

The health check for a Consul instance defaults to "/health", which is the default locations of a useful endpoint in a Spring Boot Actuator application. You need to change these, even for an Actuator application if you use a non-default context path or servlet path (e.g. server.servletPath=/foo) or management endpoint path (e.g. management.context-path=/admin). The interval that Consul uses to check the health endpoint may also be configured. "10s" and "1m" represent 10 seconds and 1 minute respectively. Example:

application.yml. 

spring:
   cloud:
     consul:
@@ -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/multi/multi_spring-cloud-consul.html b/multi/multi_spring-cloud-consul.html index d4f65e51..89684001 100644 --- a/multi/multi_spring-cloud-consul.html +++ b/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/single/spring-cloud-consul.html b/single/spring-cloud-consul.html index 3bf4ad0c..9651074a 100644 --- a/single/spring-cloud-consul.html +++ b/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

1.2.2.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 @@ -25,7 +25,7 @@ Intelligent Routing (Zuul) and Client Side Load Balancing (Ribbon), Circuit Brea consul: host: localhost port: 8500

-

[Caution]Caution

If you use Spring Cloud Consul Config, the above values will need to be placed in bootstrap.yml instead of application.yml.

The default service name, instance id and port, taken from the Environment, are ${spring.application.name}, the Spring Context ID and ${server.port} respectively.

To disable the Consul Discovery Client you can set spring.cloud.consul.discovery.enabled to false.

3.3 HTTP Health Check

The health check for a Consul instance defaults to "/health", which is the default locations of a useful endpoint in a Spring Boot Actuator application. You need to change these, even for an Actuator application if you use a non-default context path or servlet path (e.g. server.servletPath=/foo) or management endpoint path (e.g. management.context-path=/admin). The interval that Consul uses to check the health endpoint may also be configured. "10s" and "1m" represent 10 seconds and 1 minute respectively. Example:

application.yml.  +

[Caution]Caution

If you use Spring Cloud Consul Config, the above values will need to be placed in bootstrap.yml instead of application.yml.

The default service name, instance id and port, taken from the Environment, are ${spring.application.name}, the Spring Context ID and ${server.port} respectively.

To disable the Consul Discovery Client you can set spring.cloud.consul.discovery.enabled to false.

To disable the service registration you can set spring.cloud.consul.discovery.register to false.

3.3 HTTP Health Check

The health check for a Consul instance defaults to "/health", which is the default locations of a useful endpoint in a Spring Boot Actuator application. You need to change these, even for an Actuator application if you use a non-default context path or servlet path (e.g. server.servletPath=/foo) or management endpoint path (e.g. management.context-path=/admin). The interval that Consul uses to check the health endpoint may also be configured. "10s" and "1m" represent 10 seconds and 1 minute respectively. Example:

application.yml. 

spring:
   cloud:
     consul:
@@ -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,10 +65,10 @@ 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. Watching the key value store (which Consul supports) is not currently possible, but will be a future addition to this project.

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.  +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. 

spring:
   cloud:
     consul:
diff --git a/spring-cloud-consul.html b/spring-cloud-consul.html
index 91f948d4..cf781d8b 100644
--- a/spring-cloud-consul.html
+++ b/spring-cloud-consul.html
@@ -90,7 +90,7 @@ $(addBlockSwitches);
 
-

1.3.1.BUILD-SNAPSHOT

+

2.0.0.BUILD-SNAPSHOT

diff --git a/spring-cloud-consul.xml b/spring-cloud-consul.xml index 3eab0a86..81583839 100644 --- a/spring-cloud-consul.xml +++ b/spring-cloud-consul.xml @@ -4,11 +4,11 @@ Spring Cloud Consul -2017-10-17 +2017-11-28 -1.2.2.BUILD-SNAPSHOT +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 @@ -68,6 +68,7 @@ public class Application { The default service name, instance id and port, taken from the Environment, are ${spring.application.name}, the Spring Context ID and ${server.port} respectively. To disable the Consul Discovery Client you can set spring.cloud.consul.discovery.enabled to false. +To disable the service registration you can set spring.cloud.consul.discovery.register to false.
HTTP Health Check @@ -114,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; @@ -129,6 +152,7 @@ public String serviceUrl() { return null; }
+
Distributed Configuration with Consul @@ -138,7 +162,7 @@ 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. Watching the key value store (which Consul supports) is not currently possible, but will be a future addition to this project. +Configuration is currently read on startup of the application. Sending a HTTP POST to /refresh will cause the configuration to be reloaded. will also automatically detect changes and reload the application context.
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.