Eureka元數(shù)據(jù)有兩種,分別是標(biāo)準(zhǔn)元數(shù)據(jù)和自定元數(shù)據(jù)。
成都創(chuàng)新互聯(lián)公司專業(yè)提供成都主機(jī)托管四川主機(jī)托管成都服務(wù)器托管四川服務(wù)器托管,支持按月付款!我們的承諾:貴族品質(zhì)、平民價(jià)格,機(jī)房位于中國(guó)電信/網(wǎng)通/移動(dòng)機(jī)房,服務(wù)器機(jī)柜租用服務(wù)有保障!
標(biāo)準(zhǔn)元數(shù)據(jù):主機(jī)名、IP、端口號(hào)、狀態(tài)也及健康檢查等信息。這些信息會(huì)被發(fā)布在服務(wù)注冊(cè)表中,用于服務(wù)之間的調(diào)用。
自定義元數(shù)據(jù):用戶自行定義的元素,遠(yuǎn)程客戶端可訪問(wè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);用來(lái)獲取指定serviceId的服務(wù)的元數(shù)據(jù)。
3、訪問(wèn) http://localhost:8020/movie/getUserMetadata
分享文章:springCloud入門學(xué)習(xí)(四):Eureka元數(shù)據(jù)
文章來(lái)源:http://aaarwkj.com/article16/igiodg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、定制開(kāi)發(fā)、網(wǎng)頁(yè)設(shè)計(jì)公司、移動(dòng)網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)