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

Registering a product service

The product service boots up and listens on port 8081 for product service requests. We will now add the necessary instructions so that the service instance registers itself with the Eureka registry. Thanks to Spring Boot, we only have to do a few configurations and annotations:

  1. Add the dependencyManagement section with dependency on spring-cloud-netflix and the dependency in the existing dependencies section to spring-cloud-starter-eureka to the product service POM as follows:
  1. The product service keeps renewing its lease every specific interval. Reduce it to 5 seconds, by defining an entry explicitly in the application.yml as follows:
server: 
  port: 8081 
 
eureka: 
  instance: 
    leaseRenewalIntervalInSeconds: 5
  1. Include the annotation @EnableDiscoveryClient in the startup application class of the product project, in other words, ProductSpringApp. The @EnableDiscoveryClient annotation activates the Netflix Eureka DiscoveryClient implementation as that is the one we have defined in the POM file. There are other implementations for other service registries, such as HashiCorp Consul or Apache Zookeeper:
  1. Now, start the product service as before:

At the end of the initialization of the product service, you will see log statements that register the service with the Eureka server.

To check whether the product service has registered, refresh the Eureka server page that you just accessed:

Also keep a tab on the Eureka log. You will find the lease renewal log statements of the product service.

主站蜘蛛池模板: 壶关县| 信宜市| 伊金霍洛旗| 淮南市| 平阴县| 太原市| 确山县| 乌兰察布市| 土默特右旗| 麟游县| 旬阳县| 定南县| 天津市| 竹山县| 曲松县| 丹东市| 垦利县| 大竹县| 石景山区| 繁峙县| 扬州市| 郸城县| 平乐县| 长宁县| 蒲江县| 林甸县| 宁津县| 西城区| 同江市| 包头市| 商都县| 高碑店市| 南宫市| 城步| 收藏| 深水埗区| 石屏县| 富川| 申扎县| 西充县| 太白县|