Patterns such as service discovery, load balancing, and circuit breakers apply to the common abstraction layer that all spring cloud clients can consume independently of implementations (for example, through Eureka or consul Discovery).
@EnableDiscoveryClient
Commons provides @EnableDiscoveryClient comments. This is done by META-INF/spring.factories finding DiscoveryClient the implementation of the interface. The implementation of the Discovery client org.springframework.cloud.client.discovery.EnableDiscoveryClient spring.factories adds a configuration class under the key. DiscoveryClientexamples of implementations are spring cloud Netflix eureka,spring Cloud Consul Discovery and Spring Cloud zookeeper discovery.
By default, DiscoveryClient the implementation uses the remote discovery server to automatically register the local spring boot server. You can @EnableDiscoveryClient autoRegister=false disable this feature by setting it in.
Serviceregistry
Commons now provides an ServiceRegistry interface that provides methods such as register(Registration) and and deregister(Registration) the like, allowing you to provide custom registration services. Registrationis a markup interface.
@Configuration @enablediscoveryclient (Autoregister=false) Public classmyconfiguration {PrivateServiceregistry Registry; Publicmyconfiguration (Serviceregistry registry) { This. Registry =Registry; } //called via some external process, such as an event or a custom actuator endpoint Public voidRegister () {Registration Registration=constructregistration (); This. Registry.register (registration); }}
Each ServiceRegistry implementation has its own Registry implementation.
Automatic Registration of service department
By default, the ServiceRegistry implementation automatically registers the service that is running. There are two ways to disable this behavior. You can set the @EnableDiscoveryClient(autoRegister=false) automatic registration to be disabled permanently. You can also set spring.cloud.service-registry.auto-registration.enabled=false the behavior to be disabled by configuration.
Service Register Executor Endpoint
The Commons provides the actuator /service-registry endpoint. The endpoint relies on the bean in the context of the spring application Registration . /service-registry/instance-statusthe state returned by the get call Registration . Post with the String same endpoint of the principal Registration changes the current state to a new value. See the documentation for the implementation that you are using ServiceRegistry to get the allowed values for the update status and the values that are obtained for the state.
Spring Cloud Commons General Abstraction