Eureka元數(shù)據(jù)有兩種,分別是標(biāo)準(zhǔn)元數(shù)據(jù)和自定元數(shù)據(jù)。
成都創(chuàng)新互聯(lián)公司專業(yè)提供成都主機托管四川主機托管成都服務(wù)器托管四川服務(wù)器托管,支持按月付款!我們的承諾:貴族品質(zhì)、平民價格,機房位于中國電信/網(wǎng)通/移動機房,服務(wù)器機柜租用服務(wù)有保障!
標(biāo)準(zhǔn)元數(shù)據(jù):主機名、IP、端口號、狀態(tài)也及健康檢查等信息。這些信息會被發(fā)布在服務(wù)注冊表中,用于服務(wù)之間的調(diào)用。
自定義元數(shù)據(jù):用戶自行定義的元素,遠(yuǎn)程客戶端可訪問并且可以根據(jù)這些元素進(jìn)行一定的處理。
遠(yuǎn)程客戶端獲取元數(shù)據(jù):movie服務(wù)獲取user服務(wù)的元數(shù)據(jù)。
1、用戶微服務(wù)修改:
server: ??port:?8010 spring: ??application: ????name:?user eureka: ??client: ????service-url: ??????default-zone:?http://localhost:8761/eureka/ ??instance: ????prefer-ip-address:?true ????metadata-map: ??????#?自定義元數(shù)據(jù),k和v都可以隨意定義 ??????my-metadata:?user自定義元數(shù)據(jù)
2、電影服務(wù)修改:
package?com.my.movie.controller; import?com.my.movie.Util.ReturnUtil; import?lombok.extern.slf4j.Slf4j; import?org.springframework.beans.factory.annotation.Autowired; import?org.springframework.beans.factory.annotation.Value; import?org.springframework.cloud.client.ServiceInstance; import?org.springframework.cloud.client.discovery.DiscoveryClient; import?org.springframework.http.ResponseEntity; import?org.springframework.web.bind.annotation.RequestMapping; import?org.springframework.web.bind.annotation.RequestMethod; import?org.springframework.web.bind.annotation.RestController; import?org.springframework.web.client.RestTemplate; import?java.util.HashMap; import?java.util.List; import?java.util.Map; /** ?*?@author?垃圾美少女 ?*/ @RestController @Slf4j public?class?MovieController?{ ????@Autowired ????private?DiscoveryClient?discoveryClient; ????@RequestMapping(value?=?"/movie/getUserMetadata",?method?=?RequestMethod.GET) ????public?Map?getUserMetadata(){ ????????try?{ ????????????List<ServiceInstance>?user?=?discoveryClient.getInstances("user"); ????????????return?ReturnUtil.succe***esult(user,"獲取成功"); ????????}?catch?(Exception?e)?{ ????????????log.error(e.getMessage(),e); ????????????return?ReturnUtil.errorResult(null,"獲取失敗"); ????????} ????} ??? }
discoveryClient.getInstances(serviceId);用來獲取指定serviceId的服務(wù)的元數(shù)據(jù)。
3、訪問 http://localhost:8020/movie/getUserMetadata
分享文章:springCloud入門學(xué)習(xí)(四):Eureka元數(shù)據(jù)
文章來源:http://www.rwnh.cn/article16/igiodg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計公司、定制開發(fā)、網(wǎng)頁設(shè)計公司、移動網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)