日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

服务中心Eureka

發(fā)布時間:2023/12/3 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 服务中心Eureka 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一、服務(wù)消費者-注冊服務(wù)中心


測試結(jié)果

二、消費者通過Eureka訪問提供者



測試結(jié)果

Consumer

ConsumerController

package com.william.controller;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate;import javax.annotation.Resource; import java.util.List;/*** @author :lijunxuan* @date :Created in 2019/6/29 9:54* @description :* @version: 1.0*/ @RestController @RequestMapping("/consumer") public class ConsumerController {@ResourceRestTemplate restTemplate;@ResourceDiscoveryClient discoveryClient; //發(fā)現(xiàn)客戶端對象@RequestMapping("/findUser")public String findUser(Integer id){//請求服務(wù)提供者的查詢用戶詳情地址// String url="http://localhost:9091/user/findById?id="+id;alt+enter 找到formatString url= String.format("http://localhost:9091/user/findById?id=%d", id);/** 動態(tài)獲取服務(wù)注冊中心的,服務(wù)提供者地址*//*** 操作快捷鍵* 找到privider_service-> application.yml-> user-service 先復(fù)制 然后按住crtl +e 回到這個位置* discoveryClient.getInstances("user-service") ctrl +alt +v 和.var的效果相同* List<ServiceInstance> instances = discoveryClient.getInstances("user-service");*///獲取注冊中心的所有user-service用戶注冊實例List<ServiceInstance> instances = discoveryClient.getInstances("user-service");//獲取第一個實例ServiceInstance serviceInstance = instances.get(0);int port = serviceInstance.getPort();String host = serviceInstance.getHost();url= String.format("http://%s:%d/user/findById?id=%d", host, port, id);return restTemplate.getForObject(url,String.class);}}

測試斷點

服務(wù)續(xù)約


失效剔除和自我保護

總結(jié)

以上是生活随笔為你收集整理的服务中心Eureka的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。