官术网_书友最值得收藏!

  • Cloud-Native Applications in Java
  • Ajay Mahajan Munish Kumar Gupta Shyam Sundar
  • 279字
  • 2021-06-24 19:07:17

Running a service registry

Consul and Eureka are two popular dynamic service registries. There are subtle conceptual differences between them with respect to the method of heartbeats and agent-based operations, but the fundamental concept of registry is similar. The selection of the registry will be driven by the needs and the decisions of the enterprise. For our example, let's continue with Spring Boot and the Spring Cloud ecosystem and use Eureka for this example. Spring Cloud includes Spring Cloud Netflix, which has support for the Eureka registry.

Perform the following steps to get a service registry running:

  1. Create a new Maven project with artifactId as eureka-server.
  2. Edit the POM file and add the following:
    • Parent as spring-boot-starter-parent
    • The dependency to eureka-server as spring-cloud-starter-eureka-server
    • The dependencyManagement to spring-cloud-netflix:
  1. Create an application class similar to the one we created for the product project. Note the annotations. The annotation @EnableEurekaServer starts Eureka as a service:
  1. Create an application.yml file in the /product/src/main/resources folder of the application and put in the following:
server: 
  port: 8761 
  1. Create a bootstrap.yml file in the resources folder of the application and put in the following:
spring: 
  application: 
    name: eureka 
  1. Build the eureka-server Maven project (as we did for product) and then run it.
  2. Apart from a few connectivity errors (more on this later), you should see a Tomcat started message as follows:

Once the startup is completed, access the Eureka server at localhost:8761 and check whether you get the following page:

Look at the circled section in the preceding screenshot. The instance currently registered with Eureka is EUREKA itself. We can correct this later. Now, let's focus on registering our product service with this Eureka service registry.

主站蜘蛛池模板: 云林县| 兴隆县| 永清县| 固始县| 武义县| 长岭县| 温州市| 都昌县| 太白县| 溧水县| 昌平区| 康定县| 平果县| 新密市| 河源市| 日土县| 克拉玛依市| 牡丹江市| 肃北| 灌云县| 清新县| 杭锦旗| 丰顺县| 乌海市| 方山县| 闻喜县| 上犹县| 阿克陶县| 杭锦后旗| 新野县| 惠安县| 扶绥县| 九台市| 江西省| 深圳市| 当雄县| 宜春市| 南澳县| 屯门区| 高平市| 临泽县|