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 annotations. This finds the implementation of the Discoveryclient interface through Meta-inf/spring.factories. Discovery The implementation of the client will add a configuration class in the spring.factories under the Org.springframework.cloud.client.discovery.EnableDiscoveryClient key. Examples of discoveryclient implementations are spring cloud Netflix eureka,spring Cloud Consul Discovery and Spring Cloud zookeeper discovery.
By default, the implementation of Discoveryclient will automatically register the local spring boot server with the remote discovery server. You can disable this feature by setting Autoregister=false in @enablediscoveryclient.
Serviceregistry
Commons now provides a serviceregistry interface that provides methods such as register (registration) and deregister (registration) that allow you to provide custom registration services. Registration is a markup interface.
@Configurationbr/> @EnableDiscoveryClient (autoregister=false)
Private Serviceregistry Registry;
public MyConfiguration(ServiceRegistry registry) { this.registry = registry;}// called via some external process, such as an event or a custom actuator endpointpublic void register() { Registration registration = constructRegistration(); this.registry.register(registration);}
}
Each serviceregistry implementation has its own registry implementation.
Spring Cloud Commons General abstraction