Eureka is clean solution for Spring service registration and discovery. Eureka works very like Config server/client, it put all the end-points
together instead of config files
.
Eureka Server
-
Create project from Spring Initializr Don’t forget add
Eureka Server
as dependency -
Add annotation
@EnableEurekaServer
~~~java @SpringBootApplication @EnableEurekaServer public class EurekaServerApplication {public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); }
}
3. Update `application.yml`
~~~yaml
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
Eureka Client
- Add Dependency in gradle:
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
- Update the
bootstrap.yml
This is impoatant! you don’t need to change application.yml
, because we have moved the config file to the config server.
you also don’t need @EnableDiscoveryClient
or @EnableEurekaClient
.
-
Rebuild the application, and start both Eureka server and you application (in here, I am still using the
producer-helloworld-server
) -
go to
http://localhost:8761
, you should see your service listed:
Conclusion
- Same shit as Config server/config client
- No coding required