16 lines
5.0 KiB
HTML
16 lines
5.0 KiB
HTML
<html><head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
<title>71. Spring Cloud Zookeeper and Service Registry</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.html" title="Spring Cloud"><link rel="up" href="multi__spring_cloud_zookeeper.html" title="Part IX. Spring Cloud Zookeeper"><link rel="prev" href="multi_spring-cloud-zookeeper-netflix.html" title="70. Using Spring Cloud Zookeeper with Spring Cloud Netflix Components"><link rel="next" href="multi_spring-cloud-zookeeper-dependencies.html" title="72. Zookeeper Dependencies"></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">71. Spring Cloud Zookeeper and Service Registry</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi_spring-cloud-zookeeper-netflix.html">Prev</a> </td><th width="60%" align="center">Part IX. Spring Cloud Zookeeper</th><td width="20%" align="right"> <a accesskey="n" href="multi_spring-cloud-zookeeper-dependencies.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="spring-cloud-zookeeper-service-registry" href="#spring-cloud-zookeeper-service-registry"></a>71. Spring Cloud Zookeeper and Service Registry</h2></div></div></div><p>Spring Cloud Zookeeper implements the <code class="literal">ServiceRegistry</code> interface allowing developers to register arbitrary service in a programmatic way.</p><p>The <code class="literal">ServiceInstanceRegistration</code> class offers a <code class="literal">builder()</code> method to create a <code class="literal">Registration</code> object that can be used by the <code class="literal">ServiceRegistry</code>.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Autowired</span></em>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> ZookeeperServiceRegistry serviceRegistry;
|
|
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> registerThings() {
|
|
ZookeeperRegistration registration = ServiceInstanceRegistration.builder()
|
|
.defaultUriSpec()
|
|
.address(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"anyUrl"</span>)
|
|
.port(<span class="hl-number">10</span>)
|
|
.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>71.1 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> </td><td width="20%" align="center"><a accesskey="u" href="multi__spring_cloud_zookeeper.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="multi_spring-cloud-zookeeper-dependencies.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">70. Using Spring Cloud Zookeeper with Spring Cloud Netflix Components </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud.html">Home</a></td><td width="40%" align="right" valign="top"> 72. Zookeeper Dependencies</td></tr></table></div></body></html> |