Spring Cloud Spring Cloud Service Discovery & Registration 1 — Questions and Answers
Question 1: Which Spring Cloud component provides service registration and discovery using Netflix Eureka?
- Spring Cloud Config
- Spring Cloud Netflix Eureka (Correct answer)
- Spring Cloud Gateway
- Spring Cloud Sleuth
Correct answer: Spring Cloud Netflix Eureka
Spring Cloud Netflix Eureka provides a service registry where microservices register themselves and discover other services.
Question 2: What annotation is used to enable a Spring Boot application to act as a Eureka Server?
- @EnableEurekaClient
- @EnableDiscoveryClient
- @EnableEurekaServer (Correct answer)
- @EnableServiceRegistry
Correct answer: @EnableEurekaServer
@EnableEurekaServer placed on the main application class activates the Eureka Server auto-configuration.
Question 3: What is the default interval at which Eureka clients send heartbeats to the server?
- 10 seconds
- 30 seconds (Correct answer)
- 60 seconds
- 5 seconds
Correct answer: 30 seconds
By default, Eureka clients send a heartbeat every 30 seconds to renew their lease with the server.
Question 4: Which property disables Eureka registration for a Spring Boot service during local development?
- eureka.client.fetch-registry=false
- eureka.client.register-with-eureka=false (Correct answer)
- eureka.server.enabled=false
- spring.cloud.discovery.enabled=false
Correct answer: eureka.client.register-with-eureka=false
Setting eureka.client.register-with-eureka=false prevents the service from registering itself with the Eureka server.
Question 5: What mechanism does Spring Cloud use to support multiple service discovery backends like Eureka, Consul, and Zookeeper through a single API?
- Service Mesh
- DiscoveryClient abstraction (Correct answer)
- ServiceLocator pattern
- BeanDefinitionRegistry
Correct answer: DiscoveryClient abstraction
Spring Cloud's DiscoveryClient interface provides a vendor-neutral abstraction that works with Eureka, Consul, Zookeeper, and other backends.
Question 6: In Eureka's self-preservation mode, what triggers the server to stop evicting instances?
- CPU usage exceeds 80%
- Received heartbeats fall below the expected threshold (Correct answer)
- More than 10 instances are registered
- Network latency exceeds 500ms
Correct answer: Received heartbeats fall below the expected threshold
Eureka activates self-preservation mode when the percentage of received heartbeats drops below the expected threshold, preventing mass eviction during network partitions.
Which Spring Cloud component provides service registration and discovery using Netflix Eureka?