diff --git a/multi/multi_spring-cloud-zookeeper-config.html b/multi/multi_spring-cloud-zookeeper-config.html index ce984c78..42429425 100644 --- a/multi/multi_spring-cloud-zookeeper-config.html +++ b/multi/multi_spring-cloud-zookeeper-config.html @@ -4,7 +4,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 is the config/application namespace are applicable to all applications using zookeeper for configuration. Properties in the config/testApp namespace 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 configuration namespace (which Zookeeper supports) is not currently implemented, but will be a future addition to this project.
Including a dependency on org.springframework.cloud:spring-cloud-starter-zookeeper-config will enable auto-configuration that will setup Spring Cloud Zookeeper Config.
Zookeeper Config may be customized using the following properties:
bootstrap.yml. -
spring:
+spring:
cloud:
zookeeper:
config:
diff --git a/multi/multi_spring-cloud-zookeeper-dependencies.html b/multi/multi_spring-cloud-zookeeper-dependencies.html
index a6989b93..b7923674 100644
--- a/multi/multi_spring-cloud-zookeeper-dependencies.html
+++ b/multi/multi_spring-cloud-zookeeper-dependencies.html
@@ -3,7 +3,7 @@
5. Zookeeper Dependencies Spring Cloud Zookeeper gives you a possibility to provide dependencies of your application as properties. As dependencies you can understand other applications that are registered
in Zookeeper and which you would like to call via Feign (a REST client builder)
and also Spring RestTemplate.
You can also benefit from the Zookeeper Dependency Watchers functionality that lets you control and monitor what is the state of your dependencies and decide what to do with that.
- Including a dependency on
org.springframework.cloud:spring-cloud-starter-zookeeper-discovery will enable auto-configuration that will setup Spring Cloud Zookeeper Dependencies. - If you have to have the
spring.cloud.zookeeper.dependencies section properly set up - check the subsequent section for more details then the feature is active - You can have the dependencies turned off even if you’ve provided the dependencies in your properties. Just set the property
spring.cloud.zookeeper.dependency.enabled to false (defaults to true).
Let’s take a closer look at an example of dependencies representation:
application.yml.
-
spring.application.name: yourServiceName
+spring.application.name: yourServiceName
spring.cloud.zookeeper:
dependencies:
newsletter:
@@ -25,16 +25,16 @@ spring.cloud.zookeeper:
version: v1
required: true
Let’s now go through each part of the dependency one by one. The root property name is spring.cloud.zookeeper.dependencies.
Below the root property you have to represent each dependency has by an alias due to the constraints of Ribbon (the application id has to be placed in the URL
-thus you can’t pass any complex path like /foo/bar/name). The alias will be the name that you will use instead of serviceId for DiscoveryClient, Feign or RestTemplate.
In the aforementioned examples the aliases are newsletter and mailing. Example of Feign usage with newsletter would be:
@FeignClient("newsletter")
-public interface NewsletterService {
- @RequestMapping(method = RequestMethod.GET, value = "/newsletter")
+thus you can’t pass any complex path like /foo/bar/name). The alias will be the name that you will use instead of serviceId for DiscoveryClient, Feign or RestTemplate.In the aforementioned examples the aliases are newsletter and mailing. Example of Feign usage with newsletter would be:
@FeignClient("newsletter")
+public interface NewsletterService {
+ @RequestMapping(method = RequestMethod.GET, value = "/newsletter")
String getNewsletters();
}
Represented by path yaml property.
Path is the path under which the dependency is registered under Zookeeper. Like presented before Ribbon operates on URLs thus this path is not compliant with its requirement.
That is why Spring Cloud Zookeeper maps the alias to the proper path.
Represented by loadBalancerType yaml property.
If you know what kind of load balancing strategy has to be applied when calling this particular dependency then you can provide it in the yaml file and it will be automatically applied.
You can choose one of the following load balancing strategies
- STICKY - once chosen the instance will always be called
- RANDOM - picks an instance randomly
- ROUND_ROBIN - iterates over instances over and over again
Represented by contentTypeTemplate and version yaml property.
If you version your api via the Content-Type header then you don’t want to add this header to each of your requests. Also if you want to call a new version of the API you don’t want to
roam around your code to bump up the API version. That’s why you can provide a contentTypeTemplate with a special $version placeholder. That placeholder will be filled by the value of the
version yaml property. Let’s take a look at an example.
Having the following contentTypeTemplate:
application/vnd.newsletter.$version+json
and the following version:
v1
Will result in setting up of a Content-Type header for each request:
application/vnd.newsletter.v1+json
Represented by headers map in yaml
Sometimes each call to a dependency requires setting up of some default headers. In order not to do that in code you can set them up in the yaml file.
-Having the following headers section:
headers:
+Having the following headers section:headers:
Accept:
- text/html
- application/xhtml+xml
diff --git a/multi/multi_spring-cloud-zookeeper-dependency-watcher.html b/multi/multi_spring-cloud-zookeeper-dependency-watcher.html
index 3ea1f91c..ed00ff8a 100644
--- a/multi/multi_spring-cloud-zookeeper-dependency-watcher.html
+++ b/multi/multi_spring-cloud-zookeeper-dependency-watcher.html
@@ -2,7 +2,7 @@
6. Spring Cloud Zookeeper Dependency Watcher The Dependency Watcher mechanism allows you to register listeners to your dependencies. The functionality is in fact an implementation of the Observator pattern. When a dependency changes
its state (UP or DOWN) then some custom logic can be applied.
Spring Cloud Zookeeper Dependencies functionality needs to be enabled to profit from Dependency Watcher mechanism.
In order to register a listener you have to implement an interface org.springframework.cloud.zookeeper.discovery.watcher.DependencyWatcherListener and register it as a bean.
-The interface gives you one method:
void stateChanged(String dependencyName, DependencyState newState);
If you want to register a listener for a particular dependency then the dependencyName would be the discriminator for your concrete implementation. newState will provide you with information
+The interface gives you one method:
void stateChanged(String dependencyName, DependencyState newState);If you want to register a listener for a particular dependency then the dependencyName would be the discriminator for your concrete implementation. newState will provide you with information
whether your dependency has changed to CONNECTED or DISCONNECTED.
Bound with Dependency Watcher is the functionality called Presence Checker. It allows you to provide custom behaviour upon booting of your application to react accordingly to the state
of your dependencies.
The default implementation of the abstract org.springframework.cloud.zookeeper.discovery.watcher.presence.DependencyPresenceOnStartupVerifier class is the
-org.springframework.cloud.zookeeper.discovery.watcher.presence.DefaultDependencyPresenceOnStartupVerifier which works in the following way.
- If the dependency is marked us
required and it’s not in Zookeeper then upon booting your application will throw an exception and shutdown - If dependency is not
required the org.springframework.cloud.zookeeper.discovery.watcher.presence.LogMissingDependencyChecker will log that application is missing at WARN level
The functionality can be overriden since the DefaultDependencyPresenceOnStartupVerifier is registered only when there is no bean of DependencyPresenceOnStartupVerifier.