Skip to content

Commit 61199a1

Browse files
committed
Adds ServiceRegistry documentation.
fixes spring-projectsgh-170 fixes spring-projectsgh-196
1 parent 8b9821d commit 61199a1

File tree

4 files changed

+64
-5
lines changed

4 files changed

+64
-5
lines changed

docs/src/main/asciidoc/spring-cloud-commons.adoc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,33 @@ By default, implementations of `DiscoveryClient` will auto-register the local Sp
321321

322322
Commons now provides a `ServiceRegistry` interface which provides methods like `register(Registration)` and `deregister(Registration)` which allow you to provide custom registered services. `Registration` is a marker interface.
323323

324+
[source,java,indent=0]
325+
----
326+
@Configuration
327+
@EnableDiscoveryClient(autoRegister=false)
328+
public class MyConfiguration {
329+
private ServiceRegistry registry;
330+
331+
public MyConfiguration(ServiceRegistry registry) {
332+
this.registry = registry;
333+
}
334+
335+
// called via some external process, such as an event or a custom actuator endpoint
336+
public void register() {
337+
Registration registration = constructRegistration();
338+
this.registry.register(registration);
339+
}
340+
}
341+
----
342+
343+
Each `ServiceRegistry` implementation has its own `Registry` implementation.
344+
345+
346+
==== ServiceRegistry Auto-Registration
347+
348+
By default, the `ServiceRegistry` implementation will auto-register the running service. To disable that behavior, there are two methods. You can set `@EnableDiscoveryClient(autoRegister=false)` to permanently disable auto-registration. You can also set `spring.cloud.service-registry.auto-registration.enabled=false` to disable the behavior via configuration.
349+
350+
324351
==== Service Registry Actuator Endpoint
325352

326353
A `/service-registry` actuator endpoint is provided by Commons. This endpoint relys on a `Registration` bean in the Spring Application Context. Calling `/service-registry/instance-status` via a GET will return the status of the `Registration`. A POST to the same endpoint with a `String` body will change the status of the current `Registration` to the new value. Please see the documentation of the `ServiceRegistry` implementation you are using for the allowed values for updating the status and the values retured for the status.

spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/DiscoveryClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.springframework.cloud.client.ServiceInstance;
2222

2323
/**
24-
* DiscoveryClient represents operations commonly available to Discovery service such as
24+
* DiscoveryClient represents read operations commonly available to Discovery service such as
2525
* Netflix Eureka or consul.io
2626
* @author Spencer Gibb
2727
*/

spring-cloud-commons/src/main/java/org/springframework/cloud/client/serviceregistry/Registration.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package org.springframework.cloud.client.serviceregistry;
22

33
/**
4+
* A marker interface used by a {@link ServiceRegistry}.
5+
*
46
* @author Spencer Gibb
7+
* @since 1.2.0
58
*/
69
public interface Registration {
710

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,48 @@
11
package org.springframework.cloud.client.serviceregistry;
22

33
/**
4-
* TODO: write javadoc
4+
* Contract to register and deregister instances with a Service Registry.
5+
*
56
* @author Spencer Gibb
7+
* @since 1.2.0
68
*/
79
public interface ServiceRegistry<R extends Registration> {
10+
11+
/**
12+
* Register the registration. Registrations typically have information about
13+
* instances such as: hostname and port.
14+
* @param registration the registraion
15+
*/
816
void register(R registration);
917

18+
/**
19+
* Deregister the registration.
20+
* @param registration
21+
*/
1022
void deregister(R registration);
1123

24+
/**
25+
* Close the ServiceRegistry. This a lifecycle method.
26+
*/
1227
void close();
1328

14-
// TODO: return value for success?
29+
/**
30+
* Sets the status of the registration. The status values are determined
31+
* by the individual implementations.
32+
*
33+
* @see org.springframework.cloud.client.serviceregistry.endpoint.ServiceRegistryEndpoint
34+
* @param registration the registration to update
35+
* @param status the status to set
36+
*/
1537
void setStatus(R registration, String status);
1638

17-
// TODO: concrete return value? Interface?
18-
Object getStatus(R registration);
39+
/**
40+
* Gets the status of a particular registration.
41+
*
42+
* @see org.springframework.cloud.client.serviceregistry.endpoint.ServiceRegistryEndpoint
43+
* @param registration the registration to query
44+
* @param <T> the type of the status
45+
* @return the status of the registration
46+
*/
47+
<T> T getStatus(R registration);
1948
}

0 commit comments

Comments
 (0)