Sync docs from master to gh-pages

This commit is contained in:
buildmaster
2018-02-07 18:30:50 +00:00
parent 1254c6b6b1
commit bf766d539e
7 changed files with 33 additions and 39 deletions

View File

@@ -4,7 +4,7 @@
config/testApp
config/application,dev
config/application</pre><p>The most specific property source is at the top, with the least specific at the bottom. Properties is the <code class="literal">config/application</code> namespace are applicable to all applications using zookeeper for configuration. Properties in the <code class="literal">config/testApp</code> namespace are only available to the instances of the service named "testApp".</p><p>Configuration is currently read on startup of the application. Sending a HTTP POST to <code class="literal">/refresh</code> 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.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_how_to_activate_3" href="#_how_to_activate_3"></a>7.1&nbsp;How to activate</h2></div></div></div><p>Including a dependency on <code class="literal">org.springframework.cloud:spring-cloud-starter-zookeeper-config</code> will enable auto-configuration that will setup Spring Cloud Zookeeper Config.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_customizing" href="#_customizing"></a>7.2&nbsp;Customizing</h2></div></div></div><p>Zookeeper Config may be customized using the following properties:</p><p><b>bootstrap.yml.&nbsp;</b>
</p><pre class="screen">spring:
</p><pre class="programlisting">spring:
cloud:
zookeeper:
config:

View File

@@ -3,7 +3,7 @@
<title>5.&nbsp;Zookeeper Dependencies</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-zookeeper.html" title="Spring Cloud Zookeeper"><link rel="up" href="multi_spring-cloud-zookeeper.html" title="Spring Cloud Zookeeper"><link rel="prev" href="multi_spring-cloud-zookeeper-service-registry.html" title="4.&nbsp;Spring Cloud Zookeeper and Service Registry"><link rel="next" href="multi_spring-cloud-zookeeper-dependency-watcher.html" title="6.&nbsp;Spring Cloud Zookeeper Dependency Watcher"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.&nbsp;Zookeeper Dependencies</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi_spring-cloud-zookeeper-service-registry.html">Prev</a>&nbsp;</td><th width="60%" align="center">&nbsp;</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="multi_spring-cloud-zookeeper-dependency-watcher.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="spring-cloud-zookeeper-dependencies" href="#spring-cloud-zookeeper-dependencies"></a>5.&nbsp;Zookeeper Dependencies</h1></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_using_the_zookeeper_dependencies" href="#_using_the_zookeeper_dependencies"></a>5.1&nbsp;Using the Zookeeper Dependencies</h2></div></div></div><p>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 <a class="link" href="https://github.com/spring-cloud/spring-cloud-netflix/blob/master/docs/src/main/asciidoc/spring-cloud-netflix.adoc#spring-cloud-feign" target="_top">Feign</a> (a REST client builder)
and also <a class="link" href="https://github.com/spring-cloud/spring-cloud-netflix/blob/master/docs/src/main/asciidoc/spring-cloud-netflix.adoc#spring-cloud-ribbon" target="_top">Spring <code class="literal">RestTemplate</code></a>.</p><p>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.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_how_to_activate_zookeeper_dependencies" href="#_how_to_activate_zookeeper_dependencies"></a>5.2&nbsp;How to activate Zookeeper Dependencies</h2></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">Including a dependency on <code class="literal">org.springframework.cloud:spring-cloud-starter-zookeeper-discovery</code> will enable auto-configuration that will setup Spring Cloud Zookeeper Dependencies.</li><li class="listitem">If you have to have the <code class="literal">spring.cloud.zookeeper.dependencies</code> section properly set up - check the subsequent section for more details then the feature is active</li><li class="listitem">You can have the dependencies turned off even if you&#8217;ve provided the dependencies in your properties. Just set the property <code class="literal">spring.cloud.zookeeper.dependency.enabled</code> to false (defaults to <code class="literal">true</code>).</li></ul></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_setting_up_zookeeper_dependencies" href="#_setting_up_zookeeper_dependencies"></a>5.3&nbsp;Setting up Zookeeper Dependencies</h2></div></div></div><p>Let&#8217;s take a closer look at an example of dependencies representation:</p><p><b>application.yml.&nbsp;</b>
</p><pre class="screen">spring.application.name: yourServiceName
</p><pre class="programlisting">spring.application.name: yourServiceName
spring.cloud.zookeeper:
dependencies:
newsletter:
@@ -25,16 +25,16 @@ spring.cloud.zookeeper:
version: v1
required: true</pre><p>
</p><p>Let&#8217;s now go through each part of the dependency one by one. The root property name is <code class="literal">spring.cloud.zookeeper.dependencies</code>.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_aliases" href="#_aliases"></a>5.3.1&nbsp;Aliases</h3></div></div></div><p>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&#8217;t pass any complex path like /foo/bar/name). The alias will be the name that you will use instead of serviceId for <code class="literal">DiscoveryClient</code>, <code class="literal">Feign</code> or <code class="literal">RestTemplate</code>.</p><p>In the aforementioned examples the aliases are <code class="literal">newsletter</code> and <code class="literal">mailing</code>. Example of Feign usage with <code class="literal">newsletter</code> would be:</p><pre class="screen">@FeignClient("newsletter")
public interface NewsletterService {
@RequestMapping(method = RequestMethod.GET, value = "/newsletter")
thus you can&#8217;t pass any complex path like /foo/bar/name). The alias will be the name that you will use instead of serviceId for <code class="literal">DiscoveryClient</code>, <code class="literal">Feign</code> or <code class="literal">RestTemplate</code>.</p><p>In the aforementioned examples the aliases are <code class="literal">newsletter</code> and <code class="literal">mailing</code>. Example of Feign usage with <code class="literal">newsletter</code> would be:</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@FeignClient("newsletter")</span></em>
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">interface</span> NewsletterService {
<em><span class="hl-annotation" style="color: gray">@RequestMapping(method = RequestMethod.GET, value = "/newsletter")</span></em>
String getNewsletters();
}</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_path" href="#_path"></a>5.3.2&nbsp;Path</h3></div></div></div><p>Represented by <code class="literal">path</code> yaml property.</p><p>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.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_load_balancer_type" href="#_load_balancer_type"></a>5.3.3&nbsp;Load balancer type</h3></div></div></div><p>Represented by <code class="literal">loadBalancerType</code> yaml property.</p><p>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</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">STICKY - once chosen the instance will always be called</li><li class="listitem">RANDOM - picks an instance randomly</li><li class="listitem">ROUND_ROBIN - iterates over instances over and over again</li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_content_type_template_and_version" href="#_content_type_template_and_version"></a>5.3.4&nbsp;Content-Type template and version</h3></div></div></div><p>Represented by <code class="literal">contentTypeTemplate</code> and <code class="literal">version</code> yaml property.</p><p>If you version your api via the <code class="literal">Content-Type</code> header then you don&#8217;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&#8217;t want to
roam around your code to bump up the API version. That&#8217;s why you can provide a <code class="literal">contentTypeTemplate</code> with a special <code class="literal">$version</code> placeholder. That placeholder will be filled by the value of the
<code class="literal">version</code> yaml property. Let&#8217;s take a look at an example.</p><p>Having the following <code class="literal">contentTypeTemplate</code>:</p><pre class="screen">application/vnd.newsletter.$version+json</pre><p>and the following <code class="literal">version</code>:</p><pre class="screen">v1</pre><p>Will result in setting up of a <code class="literal">Content-Type</code> header for each request:</p><pre class="screen">application/vnd.newsletter.v1+json</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_default_headers" href="#_default_headers"></a>5.3.5&nbsp;Default headers</h3></div></div></div><p>Represented by <code class="literal">headers</code> map in yaml</p><p>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 <code class="literal">headers</code> section:</p><pre class="screen">headers:
Having the following <code class="literal">headers</code> section:</p><pre class="programlisting">headers:
Accept:
- text/html
- application/xhtml+xml

View File

@@ -2,7 +2,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>6.&nbsp;Spring Cloud Zookeeper Dependency Watcher</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-zookeeper.html" title="Spring Cloud Zookeeper"><link rel="up" href="multi_spring-cloud-zookeeper.html" title="Spring Cloud Zookeeper"><link rel="prev" href="multi_spring-cloud-zookeeper-dependencies.html" title="5.&nbsp;Zookeeper Dependencies"><link rel="next" href="multi_spring-cloud-zookeeper-config.html" title="7.&nbsp;Distributed Configuration with Zookeeper"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">6.&nbsp;Spring Cloud Zookeeper Dependency Watcher</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi_spring-cloud-zookeeper-dependencies.html">Prev</a>&nbsp;</td><th width="60%" align="center">&nbsp;</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="multi_spring-cloud-zookeeper-config.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="spring-cloud-zookeeper-dependency-watcher" href="#spring-cloud-zookeeper-dependency-watcher"></a>6.&nbsp;Spring Cloud Zookeeper Dependency Watcher</h1></div></div></div><p>The Dependency Watcher mechanism allows you to register listeners to your dependencies. The functionality is in fact an implementation of the <code class="literal">Observator</code> pattern. When a dependency changes
its state (UP or DOWN) then some custom logic can be applied.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_how_to_activate_2" href="#_how_to_activate_2"></a>6.1&nbsp;How to activate</h2></div></div></div><p>Spring Cloud Zookeeper Dependencies functionality needs to be enabled to profit from Dependency Watcher mechanism.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_registering_a_listener" href="#_registering_a_listener"></a>6.2&nbsp;Registering a listener</h2></div></div></div><p>In order to register a listener you have to implement an interface <code class="literal">org.springframework.cloud.zookeeper.discovery.watcher.DependencyWatcherListener</code> and register it as a bean.
The interface gives you one method:</p><pre class="screen"> void stateChanged(String dependencyName, DependencyState newState);</pre><p>If you want to register a listener for a particular dependency then the <code class="literal">dependencyName</code> would be the discriminator for your concrete implementation. <code class="literal">newState</code> will provide you with information
The interface gives you one method:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> stateChanged(String dependencyName, DependencyState newState);</pre><p>If you want to register a listener for a particular dependency then the <code class="literal">dependencyName</code> would be the discriminator for your concrete implementation. <code class="literal">newState</code> will provide you with information
whether your dependency has changed to <code class="literal">CONNECTED</code> or <code class="literal">DISCONNECTED</code>.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_presence_checker" href="#_presence_checker"></a>6.3&nbsp;Presence Checker</h2></div></div></div><p>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.</p><p>The default implementation of the abstract <code class="literal">org.springframework.cloud.zookeeper.discovery.watcher.presence.DependencyPresenceOnStartupVerifier</code> class is the
<code class="literal">org.springframework.cloud.zookeeper.discovery.watcher.presence.DefaultDependencyPresenceOnStartupVerifier</code> which works in the following way.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">If the dependency is marked us <code class="literal">required</code> and it&#8217;s not in Zookeeper then upon booting your application will throw an exception and shutdown</li><li class="listitem">If dependency is not <code class="literal">required</code> the <code class="literal">org.springframework.cloud.zookeeper.discovery.watcher.presence.LogMissingDependencyChecker</code> will log that application is missing at <code class="literal">WARN</code> level</li></ul></div><p>The functionality can be overriden since the <code class="literal">DefaultDependencyPresenceOnStartupVerifier</code> is registered only when there is no bean of <code class="literal">DependencyPresenceOnStartupVerifier</code>.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi_spring-cloud-zookeeper-dependencies.html">Prev</a>&nbsp;</td><td width="20%" align="center">&nbsp;</td><td width="40%" align="right">&nbsp;<a accesskey="n" href="multi_spring-cloud-zookeeper-config.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.&nbsp;Zookeeper Dependencies&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-zookeeper.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;7.&nbsp;Distributed Configuration with Zookeeper</td></tr></table></div></body></html>
<code class="literal">org.springframework.cloud.zookeeper.discovery.watcher.presence.DefaultDependencyPresenceOnStartupVerifier</code> which works in the following way.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">If the dependency is marked us <code class="literal">required</code> and it&#8217;s not in Zookeeper then upon booting your application will throw an exception and shutdown</li><li class="listitem">If dependency is not <code class="literal">required</code> the <code class="literal">org.springframework.cloud.zookeeper.discovery.watcher.presence.LogMissingDependencyChecker</code> will log that application is missing at <code class="literal">WARN</code> level</li></ul></div><p>The functionality can be overridden since the <code class="literal">DefaultDependencyPresenceOnStartupVerifier</code> is registered only when there is no bean of <code class="literal">DependencyPresenceOnStartupVerifier</code>.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi_spring-cloud-zookeeper-dependencies.html">Prev</a>&nbsp;</td><td width="20%" align="center">&nbsp;</td><td width="40%" align="right">&nbsp;<a accesskey="n" href="multi_spring-cloud-zookeeper-config.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.&nbsp;Zookeeper Dependencies&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-zookeeper.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;7.&nbsp;Distributed Configuration with Zookeeper</td></tr></table></div></body></html>

View File

@@ -14,7 +14,7 @@
}
}</pre><p>(i.e. utterly normal Spring Boot app). If Zookeeper is located somewhere other than <code class="literal">localhost:2181</code>, the configuration is required to locate the server. Example:</p><p><b>application.yml.&nbsp;</b>
</p><pre class="screen">spring:
</p><pre class="programlisting">spring:
cloud:
zookeeper:
connect-string: localhost:2181</pre><p>

View File

@@ -11,6 +11,4 @@
.name(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"/a/b/c/d/anotherservice"</span>)
.build();
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.serviceRegistry.register(registration);
}</pre><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_instance_status" href="#_instance_status"></a>4.1&nbsp;Instance Status</h2></div></div></div><p>Netflix Eureka supports having instances registered with the server that are <code class="literal">OUT_OF_SERVICE</code> and not returned as active service instances. This is very useful for behaviors such as blue/green deployments. The Curator Service Discovery recipe does not support this behavior. Taking advantage of the flexible payload has let Spring Cloud Zookeeper implement <code class="literal">OUT_OF_SERVICE</code> by updating some specific metadata and then filtering on that metadata in the Ribbon <code class="literal">ZookeeperServerList</code>. The <code class="literal">ZookeeperServerList</code> filters out all non-null instance statuses that do not equal <code class="literal">UP</code>. If the instance status field is empty, it is considered <code class="literal">UP</code> for backwards compatibility. To change the status of an instance POST <code class="literal">OUT_OF_SERVICE</code> to the <code class="literal">ServiceRegistry</code> instance status actuator endpoint.</p><pre class="literallayout">----
$ echo -n OUT_OF_SERVICE | http POST http://localhost:8081/service-registry/instance-status
----</pre><pre class="literallayout">NOTE: The above example uses the `http` command from https://httpie.org</pre></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi_spring-cloud-zookeeper-netflix.html">Prev</a>&nbsp;</td><td width="20%" align="center">&nbsp;</td><td width="40%" align="right">&nbsp;<a accesskey="n" href="multi_spring-cloud-zookeeper-dependencies.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">3.&nbsp;Using Spring Cloud Zookeeper with Spring Cloud Netflix Components&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-zookeeper.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;5.&nbsp;Zookeeper Dependencies</td></tr></table></div></body></html>
}</pre><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_instance_status" href="#_instance_status"></a>4.1&nbsp;Instance Status</h2></div></div></div><p>Netflix Eureka supports having instances registered with the server that are <code class="literal">OUT_OF_SERVICE</code> and not returned as active service instances. This is very useful for behaviors such as blue/green deployments. The Curator Service Discovery recipe does not support this behavior. Taking advantage of the flexible payload has let Spring Cloud Zookeeper implement <code class="literal">OUT_OF_SERVICE</code> by updating some specific metadata and then filtering on that metadata in the Ribbon <code class="literal">ZookeeperServerList</code>. The <code class="literal">ZookeeperServerList</code> filters out all non-null instance statuses that do not equal <code class="literal">UP</code>. If the instance status field is empty, it is considered <code class="literal">UP</code> for backwards compatibility. To change the status of an instance POST <code class="literal">OUT_OF_SERVICE</code> to the <code class="literal">ServiceRegistry</code> instance status actuator endpoint.</p><pre class="programlisting">$ http POST http://localhost:8081/service-registry status=OUT_OF_SERVICE</pre><pre class="literallayout">NOTE: The above example uses the `http` command from https://httpie.org</pre></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi_spring-cloud-zookeeper-netflix.html">Prev</a>&nbsp;</td><td width="20%" align="center">&nbsp;</td><td width="40%" align="right">&nbsp;<a accesskey="n" href="multi_spring-cloud-zookeeper-dependencies.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">3.&nbsp;Using Spring Cloud Zookeeper with Spring Cloud Netflix Components&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-zookeeper.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;5.&nbsp;Zookeeper Dependencies</td></tr></table></div></body></html>

View File

@@ -20,7 +20,7 @@ Intelligent Routing (Zuul) and Client Side Load Balancing (Ribbon), Circuit Brea
}
}</pre><p>(i.e. utterly normal Spring Boot app). If Zookeeper is located somewhere other than <code class="literal">localhost:2181</code>, the configuration is required to locate the server. Example:</p><p><b>application.yml.&nbsp;</b>
</p><pre class="screen">spring:
</p><pre class="programlisting">spring:
cloud:
zookeeper:
connect-string: localhost:2181</pre><p>
@@ -44,12 +44,10 @@ Intelligent Routing (Zuul) and Client Side Load Balancing (Ribbon), Circuit Brea
.name(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"/a/b/c/d/anotherservice"</span>)
.build();
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.serviceRegistry.register(registration);
}</pre><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_instance_status" href="#_instance_status"></a>4.1&nbsp;Instance Status</h2></div></div></div><p>Netflix Eureka supports having instances registered with the server that are <code class="literal">OUT_OF_SERVICE</code> and not returned as active service instances. This is very useful for behaviors such as blue/green deployments. The Curator Service Discovery recipe does not support this behavior. Taking advantage of the flexible payload has let Spring Cloud Zookeeper implement <code class="literal">OUT_OF_SERVICE</code> by updating some specific metadata and then filtering on that metadata in the Ribbon <code class="literal">ZookeeperServerList</code>. The <code class="literal">ZookeeperServerList</code> filters out all non-null instance statuses that do not equal <code class="literal">UP</code>. If the instance status field is empty, it is considered <code class="literal">UP</code> for backwards compatibility. To change the status of an instance POST <code class="literal">OUT_OF_SERVICE</code> to the <code class="literal">ServiceRegistry</code> instance status actuator endpoint.</p><pre class="literallayout">----
$ echo -n OUT_OF_SERVICE | http POST http://localhost:8081/service-registry/instance-status
----</pre><pre class="literallayout">NOTE: The above example uses the `http` command from https://httpie.org</pre></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="spring-cloud-zookeeper-dependencies" href="#spring-cloud-zookeeper-dependencies"></a>5.&nbsp;Zookeeper Dependencies</h1></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_using_the_zookeeper_dependencies" href="#_using_the_zookeeper_dependencies"></a>5.1&nbsp;Using the Zookeeper Dependencies</h2></div></div></div><p>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
}</pre><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_instance_status" href="#_instance_status"></a>4.1&nbsp;Instance Status</h2></div></div></div><p>Netflix Eureka supports having instances registered with the server that are <code class="literal">OUT_OF_SERVICE</code> and not returned as active service instances. This is very useful for behaviors such as blue/green deployments. The Curator Service Discovery recipe does not support this behavior. Taking advantage of the flexible payload has let Spring Cloud Zookeeper implement <code class="literal">OUT_OF_SERVICE</code> by updating some specific metadata and then filtering on that metadata in the Ribbon <code class="literal">ZookeeperServerList</code>. The <code class="literal">ZookeeperServerList</code> filters out all non-null instance statuses that do not equal <code class="literal">UP</code>. If the instance status field is empty, it is considered <code class="literal">UP</code> for backwards compatibility. To change the status of an instance POST <code class="literal">OUT_OF_SERVICE</code> to the <code class="literal">ServiceRegistry</code> instance status actuator endpoint.</p><pre class="programlisting">$ http POST http://localhost:8081/service-registry status=OUT_OF_SERVICE</pre><pre class="literallayout">NOTE: The above example uses the `http` command from https://httpie.org</pre></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="spring-cloud-zookeeper-dependencies" href="#spring-cloud-zookeeper-dependencies"></a>5.&nbsp;Zookeeper Dependencies</h1></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_using_the_zookeeper_dependencies" href="#_using_the_zookeeper_dependencies"></a>5.1&nbsp;Using the Zookeeper Dependencies</h2></div></div></div><p>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 <a class="link" href="https://github.com/spring-cloud/spring-cloud-netflix/blob/master/docs/src/main/asciidoc/spring-cloud-netflix.adoc#spring-cloud-feign" target="_top">Feign</a> (a REST client builder)
and also <a class="link" href="https://github.com/spring-cloud/spring-cloud-netflix/blob/master/docs/src/main/asciidoc/spring-cloud-netflix.adoc#spring-cloud-ribbon" target="_top">Spring <code class="literal">RestTemplate</code></a>.</p><p>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.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_how_to_activate_zookeeper_dependencies" href="#_how_to_activate_zookeeper_dependencies"></a>5.2&nbsp;How to activate Zookeeper Dependencies</h2></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">Including a dependency on <code class="literal">org.springframework.cloud:spring-cloud-starter-zookeeper-discovery</code> will enable auto-configuration that will setup Spring Cloud Zookeeper Dependencies.</li><li class="listitem">If you have to have the <code class="literal">spring.cloud.zookeeper.dependencies</code> section properly set up - check the subsequent section for more details then the feature is active</li><li class="listitem">You can have the dependencies turned off even if you&#8217;ve provided the dependencies in your properties. Just set the property <code class="literal">spring.cloud.zookeeper.dependency.enabled</code> to false (defaults to <code class="literal">true</code>).</li></ul></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_setting_up_zookeeper_dependencies" href="#_setting_up_zookeeper_dependencies"></a>5.3&nbsp;Setting up Zookeeper Dependencies</h2></div></div></div><p>Let&#8217;s take a closer look at an example of dependencies representation:</p><p><b>application.yml.&nbsp;</b>
</p><pre class="screen">spring.application.name: yourServiceName
</p><pre class="programlisting">spring.application.name: yourServiceName
spring.cloud.zookeeper:
dependencies:
newsletter:
@@ -71,16 +69,16 @@ spring.cloud.zookeeper:
version: v1
required: true</pre><p>
</p><p>Let&#8217;s now go through each part of the dependency one by one. The root property name is <code class="literal">spring.cloud.zookeeper.dependencies</code>.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_aliases" href="#_aliases"></a>5.3.1&nbsp;Aliases</h3></div></div></div><p>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&#8217;t pass any complex path like /foo/bar/name). The alias will be the name that you will use instead of serviceId for <code class="literal">DiscoveryClient</code>, <code class="literal">Feign</code> or <code class="literal">RestTemplate</code>.</p><p>In the aforementioned examples the aliases are <code class="literal">newsletter</code> and <code class="literal">mailing</code>. Example of Feign usage with <code class="literal">newsletter</code> would be:</p><pre class="screen">@FeignClient("newsletter")
public interface NewsletterService {
@RequestMapping(method = RequestMethod.GET, value = "/newsletter")
thus you can&#8217;t pass any complex path like /foo/bar/name). The alias will be the name that you will use instead of serviceId for <code class="literal">DiscoveryClient</code>, <code class="literal">Feign</code> or <code class="literal">RestTemplate</code>.</p><p>In the aforementioned examples the aliases are <code class="literal">newsletter</code> and <code class="literal">mailing</code>. Example of Feign usage with <code class="literal">newsletter</code> would be:</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@FeignClient("newsletter")</span></em>
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">interface</span> NewsletterService {
<em><span class="hl-annotation" style="color: gray">@RequestMapping(method = RequestMethod.GET, value = "/newsletter")</span></em>
String getNewsletters();
}</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_path" href="#_path"></a>5.3.2&nbsp;Path</h3></div></div></div><p>Represented by <code class="literal">path</code> yaml property.</p><p>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.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_load_balancer_type" href="#_load_balancer_type"></a>5.3.3&nbsp;Load balancer type</h3></div></div></div><p>Represented by <code class="literal">loadBalancerType</code> yaml property.</p><p>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</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">STICKY - once chosen the instance will always be called</li><li class="listitem">RANDOM - picks an instance randomly</li><li class="listitem">ROUND_ROBIN - iterates over instances over and over again</li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_content_type_template_and_version" href="#_content_type_template_and_version"></a>5.3.4&nbsp;Content-Type template and version</h3></div></div></div><p>Represented by <code class="literal">contentTypeTemplate</code> and <code class="literal">version</code> yaml property.</p><p>If you version your api via the <code class="literal">Content-Type</code> header then you don&#8217;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&#8217;t want to
roam around your code to bump up the API version. That&#8217;s why you can provide a <code class="literal">contentTypeTemplate</code> with a special <code class="literal">$version</code> placeholder. That placeholder will be filled by the value of the
<code class="literal">version</code> yaml property. Let&#8217;s take a look at an example.</p><p>Having the following <code class="literal">contentTypeTemplate</code>:</p><pre class="screen">application/vnd.newsletter.$version+json</pre><p>and the following <code class="literal">version</code>:</p><pre class="screen">v1</pre><p>Will result in setting up of a <code class="literal">Content-Type</code> header for each request:</p><pre class="screen">application/vnd.newsletter.v1+json</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_default_headers" href="#_default_headers"></a>5.3.5&nbsp;Default headers</h3></div></div></div><p>Represented by <code class="literal">headers</code> map in yaml</p><p>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 <code class="literal">headers</code> section:</p><pre class="screen">headers:
Having the following <code class="literal">headers</code> section:</p><pre class="programlisting">headers:
Accept:
- text/html
- application/xhtml+xml
@@ -93,14 +91,14 @@ actually be the alias that has to be resolved to a proper path in Zookeeper. Wit
types with version as presented in the Dependency configuration. Without this setting of those two parameters will not be operational.</li><li class="listitem"><code class="literal">spring.cloud.zookeeper.dependency.resttemplate.enabled</code> (enabled by default) - when enabled will modify the request headers of <code class="literal">@LoadBalanced</code> annotated <code class="literal">RestTemplate</code> so that it passes
headers and content type with version set in Dependency configuration. Wihtout this setting of those two parameters will not be operational.</li></ul></div></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="spring-cloud-zookeeper-dependency-watcher" href="#spring-cloud-zookeeper-dependency-watcher"></a>6.&nbsp;Spring Cloud Zookeeper Dependency Watcher</h1></div></div></div><p>The Dependency Watcher mechanism allows you to register listeners to your dependencies. The functionality is in fact an implementation of the <code class="literal">Observator</code> pattern. When a dependency changes
its state (UP or DOWN) then some custom logic can be applied.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_how_to_activate_2" href="#_how_to_activate_2"></a>6.1&nbsp;How to activate</h2></div></div></div><p>Spring Cloud Zookeeper Dependencies functionality needs to be enabled to profit from Dependency Watcher mechanism.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_registering_a_listener" href="#_registering_a_listener"></a>6.2&nbsp;Registering a listener</h2></div></div></div><p>In order to register a listener you have to implement an interface <code class="literal">org.springframework.cloud.zookeeper.discovery.watcher.DependencyWatcherListener</code> and register it as a bean.
The interface gives you one method:</p><pre class="screen"> void stateChanged(String dependencyName, DependencyState newState);</pre><p>If you want to register a listener for a particular dependency then the <code class="literal">dependencyName</code> would be the discriminator for your concrete implementation. <code class="literal">newState</code> will provide you with information
The interface gives you one method:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> stateChanged(String dependencyName, DependencyState newState);</pre><p>If you want to register a listener for a particular dependency then the <code class="literal">dependencyName</code> would be the discriminator for your concrete implementation. <code class="literal">newState</code> will provide you with information
whether your dependency has changed to <code class="literal">CONNECTED</code> or <code class="literal">DISCONNECTED</code>.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_presence_checker" href="#_presence_checker"></a>6.3&nbsp;Presence Checker</h2></div></div></div><p>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.</p><p>The default implementation of the abstract <code class="literal">org.springframework.cloud.zookeeper.discovery.watcher.presence.DependencyPresenceOnStartupVerifier</code> class is the
<code class="literal">org.springframework.cloud.zookeeper.discovery.watcher.presence.DefaultDependencyPresenceOnStartupVerifier</code> which works in the following way.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">If the dependency is marked us <code class="literal">required</code> and it&#8217;s not in Zookeeper then upon booting your application will throw an exception and shutdown</li><li class="listitem">If dependency is not <code class="literal">required</code> the <code class="literal">org.springframework.cloud.zookeeper.discovery.watcher.presence.LogMissingDependencyChecker</code> will log that application is missing at <code class="literal">WARN</code> level</li></ul></div><p>The functionality can be overriden since the <code class="literal">DefaultDependencyPresenceOnStartupVerifier</code> is registered only when there is no bean of <code class="literal">DependencyPresenceOnStartupVerifier</code>.</p></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="spring-cloud-zookeeper-config" href="#spring-cloud-zookeeper-config"></a>7.&nbsp;Distributed Configuration with Zookeeper</h1></div></div></div><p>Zookeeper provides a <a class="link" href="http://zookeeper.apache.org/doc/current/zookeeperOver.html#sc_dataModelNameSpace" target="_top">hierarchical namespace</a> that allows clients to store arbitrary data, such as configuration data. Spring Cloud Zookeeper Config is an alternative to the <a class="link" href="https://github.com/spring-cloud/spring-cloud-config" target="_top">Config Server and Client</a>. Configuration is loaded into the Spring Environment during the special "bootstrap" phase. Configuration is stored in the <code class="literal">/config</code> namespace by default. Multiple <code class="literal">PropertySource</code> instances are created based on the application&#8217;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:</p><pre class="screen">config/testApp,dev
<code class="literal">org.springframework.cloud.zookeeper.discovery.watcher.presence.DefaultDependencyPresenceOnStartupVerifier</code> which works in the following way.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">If the dependency is marked us <code class="literal">required</code> and it&#8217;s not in Zookeeper then upon booting your application will throw an exception and shutdown</li><li class="listitem">If dependency is not <code class="literal">required</code> the <code class="literal">org.springframework.cloud.zookeeper.discovery.watcher.presence.LogMissingDependencyChecker</code> will log that application is missing at <code class="literal">WARN</code> level</li></ul></div><p>The functionality can be overridden since the <code class="literal">DefaultDependencyPresenceOnStartupVerifier</code> is registered only when there is no bean of <code class="literal">DependencyPresenceOnStartupVerifier</code>.</p></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="spring-cloud-zookeeper-config" href="#spring-cloud-zookeeper-config"></a>7.&nbsp;Distributed Configuration with Zookeeper</h1></div></div></div><p>Zookeeper provides a <a class="link" href="http://zookeeper.apache.org/doc/current/zookeeperOver.html#sc_dataModelNameSpace" target="_top">hierarchical namespace</a> that allows clients to store arbitrary data, such as configuration data. Spring Cloud Zookeeper Config is an alternative to the <a class="link" href="https://github.com/spring-cloud/spring-cloud-config" target="_top">Config Server and Client</a>. Configuration is loaded into the Spring Environment during the special "bootstrap" phase. Configuration is stored in the <code class="literal">/config</code> namespace by default. Multiple <code class="literal">PropertySource</code> instances are created based on the application&#8217;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:</p><pre class="screen">config/testApp,dev
config/testApp
config/application,dev
config/application</pre><p>The most specific property source is at the top, with the least specific at the bottom. Properties is the <code class="literal">config/application</code> namespace are applicable to all applications using zookeeper for configuration. Properties in the <code class="literal">config/testApp</code> namespace are only available to the instances of the service named "testApp".</p><p>Configuration is currently read on startup of the application. Sending a HTTP POST to <code class="literal">/refresh</code> 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.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_how_to_activate_3" href="#_how_to_activate_3"></a>7.1&nbsp;How to activate</h2></div></div></div><p>Including a dependency on <code class="literal">org.springframework.cloud:spring-cloud-starter-zookeeper-config</code> will enable auto-configuration that will setup Spring Cloud Zookeeper Config.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_customizing" href="#_customizing"></a>7.2&nbsp;Customizing</h2></div></div></div><p>Zookeeper Config may be customized using the following properties:</p><p><b>bootstrap.yml.&nbsp;</b>
</p><pre class="screen">spring:
</p><pre class="programlisting">spring:
cloud:
zookeeper:
config:

View File

@@ -52,10 +52,10 @@ public class Application {
<formalpara>
<title>application.yml</title>
<para>
<screen>spring:
<programlisting language="yml" linenumbering="unnumbered">spring:
cloud:
zookeeper:
connect-string: localhost:2181</screen>
connect-string: localhost:2181</programlisting>
</para>
</formalpara>
<caution>
@@ -108,9 +108,7 @@ public void registerThings() {
<section xml:id="_instance_status">
<title>Instance Status</title>
<simpara>Netflix Eureka supports having instances registered with the server that are <literal>OUT_OF_SERVICE</literal> and not returned as active service instances. This is very useful for behaviors such as blue/green deployments. The Curator Service Discovery recipe does not support this behavior. Taking advantage of the flexible payload has let Spring Cloud Zookeeper implement <literal>OUT_OF_SERVICE</literal> by updating some specific metadata and then filtering on that metadata in the Ribbon <literal>ZookeeperServerList</literal>. The <literal>ZookeeperServerList</literal> filters out all non-null instance statuses that do not equal <literal>UP</literal>. If the instance status field is empty, it is considered <literal>UP</literal> for backwards compatibility. To change the status of an instance POST <literal>OUT_OF_SERVICE</literal> to the <literal>ServiceRegistry</literal> instance status actuator endpoint.</simpara>
<literallayout class="monospaced">----
$ echo -n OUT_OF_SERVICE | http POST http://localhost:8081/service-registry/instance-status
----</literallayout>
<programlisting language="sh" linenumbering="unnumbered">$ http POST http://localhost:8081/service-registry status=OUT_OF_SERVICE</programlisting>
<literallayout class="monospaced">NOTE: The above example uses the `http` command from https://httpie.org</literallayout>
</section>
</chapter>
@@ -143,7 +141,7 @@ and also <link xl:href="https://github.com/spring-cloud/spring-cloud-netflix/blo
<formalpara>
<title>application.yml</title>
<para>
<screen>spring.application.name: yourServiceName
<programlisting language="yml" linenumbering="unnumbered">spring.application.name: yourServiceName
spring.cloud.zookeeper:
dependencies:
newsletter:
@@ -163,7 +161,7 @@ spring.cloud.zookeeper:
loadBalancerType: ROUND_ROBIN
contentTypeTemplate: application/vnd.mailing.$version+json
version: v1
required: true</screen>
required: true</programlisting>
</para>
</formalpara>
<simpara>Let&#8217;s now go through each part of the dependency one by one. The root property name is <literal>spring.cloud.zookeeper.dependencies</literal>.</simpara>
@@ -172,11 +170,11 @@ spring.cloud.zookeeper:
<simpara>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&#8217;t pass any complex path like /foo/bar/name). The alias will be the name that you will use instead of serviceId for <literal>DiscoveryClient</literal>, <literal>Feign</literal> or <literal>RestTemplate</literal>.</simpara>
<simpara>In the aforementioned examples the aliases are <literal>newsletter</literal> and <literal>mailing</literal>. Example of Feign usage with <literal>newsletter</literal> would be:</simpara>
<screen>@FeignClient("newsletter")
<programlisting language="java" linenumbering="unnumbered">@FeignClient("newsletter")
public interface NewsletterService {
@RequestMapping(method = RequestMethod.GET, value = "/newsletter")
String getNewsletters();
}</screen>
}</programlisting>
</section>
<section xml:id="_path">
<title>Path</title>
@@ -219,12 +217,12 @@ roam around your code to bump up the API version. That&#8217;s why you can provi
<simpara>Represented by <literal>headers</literal> map in yaml</simpara>
<simpara>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 <literal>headers</literal> section:</simpara>
<screen>headers:
<programlisting language="yml" linenumbering="unnumbered">headers:
Accept:
- text/html
- application/xhtml+xml
Cache-Control:
- no-cache</screen>
- no-cache</programlisting>
<simpara>Results in adding the <literal>Accept</literal> and <literal>Cache-Control</literal> headers with appropriate list of values in your HTTP request.</simpara>
</section>
<section xml:id="_obligatory_dependencies">
@@ -295,7 +293,7 @@ its state (UP or DOWN) then some custom logic can be applied.</simpara>
<title>Registering a listener</title>
<simpara>In order to register a listener you have to implement an interface <literal>org.springframework.cloud.zookeeper.discovery.watcher.DependencyWatcherListener</literal> and register it as a bean.
The interface gives you one method:</simpara>
<screen> void stateChanged(String dependencyName, DependencyState newState);</screen>
<programlisting language="java" linenumbering="unnumbered">void stateChanged(String dependencyName, DependencyState newState);</programlisting>
<simpara>If you want to register a listener for a particular dependency then the <literal>dependencyName</literal> would be the discriminator for your concrete implementation. <literal>newState</literal> will provide you with information
whether your dependency has changed to <literal>CONNECTED</literal> or <literal>DISCONNECTED</literal>.</simpara>
</section>
@@ -313,7 +311,7 @@ of your dependencies.</simpara>
<simpara>If dependency is not <literal>required</literal> the <literal>org.springframework.cloud.zookeeper.discovery.watcher.presence.LogMissingDependencyChecker</literal> will log that application is missing at <literal>WARN</literal> level</simpara>
</listitem>
</itemizedlist>
<simpara>The functionality can be overriden since the <literal>DefaultDependencyPresenceOnStartupVerifier</literal> is registered only when there is no bean of <literal>DependencyPresenceOnStartupVerifier</literal>.</simpara>
<simpara>The functionality can be overridden since the <literal>DefaultDependencyPresenceOnStartupVerifier</literal> is registered only when there is no bean of <literal>DependencyPresenceOnStartupVerifier</literal>.</simpara>
</section>
</chapter>
<chapter xml:id="spring-cloud-zookeeper-config">
@@ -335,14 +333,14 @@ config/application</screen>
<formalpara>
<title>bootstrap.yml</title>
<para>
<screen>spring:
<programlisting language="yml" linenumbering="unnumbered">spring:
cloud:
zookeeper:
config:
enabled: true
root: configuration
defaultContext: apps
profileSeparator: '::'</screen>
profileSeparator: '::'</programlisting>
</para>
</formalpara>
<itemizedlist>