Service registration and discovery
What Is Service Discovery?
A microservices-based application typically runs in virtualized or containerized environments. The number of instances of a service and its locations changes dynamically. We need to know where these instances are and their names to allow requests to arrive at the target microservice.
The Service Discovery mechanism helps us know where each instance is located. In this way, a Service Discovery component acts as a registry in which the addresses of all instances are tracked. The instances have dynamically assigned network paths. Consequently, if a client wants to make a request to a service, it must use a Service Discovery mechanism.
Features and uses
- Register and find services
- Provides network location, IP and port details
Implementation details
@EnableDiscoveryClient
Spring Cloud Commons provides the @EnableDiscoveryClient
annotation. This looks for implementations of the DiscoveryClient
interface with META-INF/spring.factories
. Implementations of the Discovery Client add a configuration class to spring.factories
under the org.springframework.cloud.client.discovery.EnableDiscoveryClient key
. Examples of DiscoveryClient
implementations include
By default, implementations of DiscoveryClient
auto-register the local Spring Boot server with the remote discovery server. This behavior can be disabled by setting autoRegister=false
in @EnableDiscoveryClient
.
- Spring Cloud Netflix,
-
https://spring.io/guides/gs/service-registration-and-discovery/
With this implementation, the
@EnableDiscoveryClient
activates the Netflix Eureka DiscoveryClient implementation.
-
- Spring Cloud Consul
- Spring Cloud Zookeeper
A service registry is useful because it enables client-side load-balancing and decouples service providers from consumers without the need for DNS.
Some systems such as Kubernetes, Marathon and AWS ELB have an implicit service registry.