Eureka Flashcards
What is Eureka?
Eureka is a service discovery implementation
If spring-cloud-starter-netflix-eureka-client
is on the classpath, are there any annotations needed to connect to a Eureka server?
No. A Eureka client automatically connects to http://localhost:8761/eureka/
HTTP basic authentication is automatically added to your eureka client if one of the eureka.client.serviceUrl.defaultZone
URLs has credentials embedded in it (curl style, as follows: user:password@localhost:8761/eureka).
By default, the EurekaClient bean is refreshable, meaning the Eureka client properties can be changed and refreshed. When a refresh occurs clients will be unregistered from the Eureka server and there might be a brief moment of time where all instance of a given service are not available. One way to eliminate this from happening is to disable the ability to refresh Eureka clients. To do this set eureka.client.refresh.enable=false.
If you want to run Eureka Client in AOT or native image modes, make sure to set spring.cloud.refresh.enabled to false
spring.application.name
is used to give each microservice a virtual hostname, a name used by the Eureka server to identify each microservice. Eureka clients will use this virtual hostname in the URLs that are used to make HTTP calls to the microservice (e.g. http://service-a). This will only work if the HTTP client is load balanced
What annotation is required on a configuration class to enable a Eureka server?
@EnableEurekaServer
The server has a home page with a UI and REST API endpoints for the normal Eureka functionality under /eureka/*
Eureka implements client-side service discovery and Kubernetes implements server-side service discovery
By default, how often do Eureka clients send a heartbeat to the Eureka server?
Every 30 seconds
Eureka clients have an in-memory cache of Eureka registrations so they do not have to go to the registry for every request to a service
By default, every Eureka server is also a Eureka client and requires (at least one) service URL to locate a peer. If you do not provide it, the service runs and works, but it fills your logs with a lot of noise about not being able to register with the peer. To prevent this, you can run a standalone Eureka server with the following properties:
eureka: client: register-with-eureka: false fetch-registry: false
A standalone Eureka server is fairly resilient to failure as long as there is some sort of monitor or elastic runtime (such as Cloud Foundry) keeping it alive
Eureka can be made even more resilient and available by running multiple instances and asking them to register with each other. In fact, this is the default behavior, so all you need to do to make it work is add a valid serviceUrl to a peer, as shown in the following example:
--- spring: profiles: peer1 eureka: instance: hostname: peer1 client: serviceUrl: defaultZone: https://peer2/eureka/ --- spring: profiles: peer2 eureka: instance: hostname: peer2 client: serviceUrl: defaultZone: https://peer1/eureka/
You can add multiple Eureka server peers to a system, and as long as they are all directly connected to each other, they will synchronize the registrations amongst themselves.