- Cloud-Native Applications in Java
- Ajay Mahajan Munish Kumar Gupta Shyam Sundar
- 229字
- 2021-06-24 19:07:18
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:
- 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:

- 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
- 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:

- 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.
推薦閱讀
- 協(xié)同通信技術(shù)
- LED封裝與檢測技術(shù)
- 室內(nèi)分布系統(tǒng)規(guī)劃與設(shè)計:GSM/TD-SCDMA/TD-LTE/WLAN
- Android音視頻開發(fā)
- 2018—2019年中國無線電應(yīng)用與管理藍(lán)皮書
- 可見光通信光源與探測器件原理及應(yīng)用
- 數(shù)據(jù)鏈理論與系統(tǒng)
- 智能電網(wǎng)技術(shù):面向供需互動能量優(yōu)化
- SMT工藝與PCB制造(電子技術(shù)輕松學(xué))
- 區(qū)域智能電網(wǎng)的規(guī)劃方法
- 光接入網(wǎng)實用技術(shù)
- 圖解液晶電視機(jī)電源板維修實戰(zhàn)
- 現(xiàn)代交換原理與技術(shù)(第2版)
- 3G知識問答
- 5G網(wǎng)絡(luò)建設(shè)實踐與模式創(chuàng)新