Spring Cloud Consul的服務注冊與發(fā)現(xiàn)
以Windows為例,下載解壓后,以開發(fā)模式運行:
consul agent --dev
啟動成功后,可以訪問Consul提供的管理頁面,默認端口為8500,頁面上顯示了已注冊服務的列表,包括它們的運行狀況等信息。
<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-consul-discovery</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency></dependencies>2.在服務配置文件中添加Consul配置:
spring: cloud: consul: host: localhost port: 85003.運行消費者和提供者服務,Consul管理頁面將顯示對應的服務信息:
使用RestTemplate調用服務
@AutowiredRestTemplate restTemplate;public String getFirstProduct() { return this.restTemplate.getForObject('https://服務名/products/1', String.class);}
要使用RestTemplate別忘了加配置:
@Bean@LoadBalancedpublic RestTemplate restTemplate(){return new RestTemplate();}
以上就是Spring Cloud Consul的服務注冊與發(fā)現(xiàn)的詳細內容,更多關于Spring Cloud Consul 服務注冊與發(fā)現(xiàn)的資料請關注好吧啦網(wǎng)其它相關文章!
相關文章:
1. 一款功能強大的markdown編輯器tui.editor使用示例詳解2. 利用CSS制作3D動畫3. Python+unittest+requests 接口自動化測試框架搭建教程4. Springboot 全局日期格式化處理的實現(xiàn)5. Python 實現(xiàn)勞拉游戲的實例代碼(四連環(huán)、重力四子棋)6. SpringBoot+TestNG單元測試的實現(xiàn)7. .Net加密神器Eazfuscator.NET?2023.2?最新版使用教程8. Java GZip 基于內存實現(xiàn)壓縮和解壓的方法9. 存儲于xml中需要的HTML轉義代碼10. jsp+servlet簡單實現(xiàn)上傳文件功能(保存目錄改進)
