Spring Cloud Consul的服務(wù)注冊與發(fā)現(xiàn)
以Windows為例,下載解壓后,以開發(fā)模式運(yùn)行:
consul agent --dev
啟動成功后,可以訪問Consul提供的管理頁面,默認(rèn)端口為8500,頁面上顯示了已注冊服務(wù)的列表,包括它們的運(yùn)行狀況等信息。
<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.在服務(wù)配置文件中添加Consul配置:
spring: cloud: consul: host: localhost port: 85003.運(yùn)行消費(fèi)者和提供者服務(wù),Consul管理頁面將顯示對應(yīng)的服務(wù)信息:
使用RestTemplate調(diào)用服務(wù)
@AutowiredRestTemplate restTemplate;public String getFirstProduct() { return this.restTemplate.getForObject('https://服務(wù)名/products/1', String.class);}
要使用RestTemplate別忘了加配置:
@Bean@LoadBalancedpublic RestTemplate restTemplate(){return new RestTemplate();}
以上就是Spring Cloud Consul的服務(wù)注冊與發(fā)現(xiàn)的詳細(xì)內(nèi)容,更多關(guān)于Spring Cloud Consul 服務(wù)注冊與發(fā)現(xiàn)的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. ASP基礎(chǔ)知識VBScript基本元素講解2. Python requests庫參數(shù)提交的注意事項(xiàng)總結(jié)3. IntelliJ IDEA導(dǎo)入jar包的方法4. ajax請求添加自定義header參數(shù)代碼5. Kotlin + Flow 實(shí)現(xiàn)Android 應(yīng)用初始化任務(wù)啟動庫6. 利用CSS3新特性創(chuàng)建透明邊框三角7. python操作mysql、excel、pdf的示例8. 詳談ajax返回數(shù)據(jù)成功 卻進(jìn)入error的方法9. 使用python 計(jì)算百分位數(shù)實(shí)現(xiàn)數(shù)據(jù)分箱代碼10. 使用Python和百度語音識別生成視頻字幕的實(shí)現(xiàn)
