- Mastering Spring Cloud
- Piotr Minkowski
- 242字
- 2021-08-27 18:57:08
Adding a Eureka Server
As you have probably noticed, there is the discovery service network location address in the client's properties. So, before launching the client service we should have a Eureka Server running. Of course, Eureka also has its own configuration, which has been stored in the application.yml file for the example from the previous chapter. That configuration, similar to client-service, has been divided into three profiles, where each of them differ from the others in such properties as the number of the server's HTTP port and the list of discovery peers to communicate with.
Now, we place those property files on the configuration server. Eureka fetches all of the settings assigned to the selected profile on startup. File naming is consistent with the already described standard, which means discovery-service-zone[n].yml. Before running the Eureka Server, we should include spring-cloud-starter-config in the dependencies to enable Spring Cloud Config Client, and replace application.yml with bootstrap.yml, which is shown here:
spring:
application:
name: discovery-service
cloud:
config:
uri: http://localhost:8889
Now, we may run three instances of the Eureka Server in peer-to-peer communication mode by setting a different profile name in the --spring.profiles.active property. After launching three instances of client-service, our architecture looks like the following diagram. In comparison to the example from the previous chapter, both client and discovery services fetch the configuration from the Spring Cloud Config Server, instead of keeping it as a YML file inside a fat JAR: