提交 0241a2f9 authored 作者: 王健's avatar 王健

DiscoveryClient

上级 55c9d0c6
...@@ -3,11 +3,15 @@ package com.xcloud.galaxy.movieservice.controller; ...@@ -3,11 +3,15 @@ package com.xcloud.galaxy.movieservice.controller;
import com.xcloud.galaxy.userservice.entity.User; import com.xcloud.galaxy.userservice.entity.User;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; 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.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.util.List;
/** /**
* @Description * @Description
* @Author wangjian * @Author wangjian
...@@ -22,6 +26,9 @@ public class MovieController { ...@@ -22,6 +26,9 @@ public class MovieController {
@Autowired @Autowired
private RestTemplate restTemplate; private RestTemplate restTemplate;
@Autowired
private DiscoveryClient discoveryClient;
@GetMapping(value = "/index") @GetMapping(value = "/index")
public User index() { public User index() {
...@@ -30,4 +37,48 @@ public class MovieController { ...@@ -30,4 +37,48 @@ public class MovieController {
} }
/**
* [
* {
* "serviceId": "user-service",
* "host": "192.168.6.239",
* "port": 8071,
* "secure": false,
* "metadata": {
* "nacos.instanceId": "192.168.6.239#8071#DEFAULT#DEFAULT_GROUP@@user-service",
* "nacos.weight": "1.0",
* "nacos.cluster": "DEFAULT",
* "nacos.healthy": "true",
* "preserved.register.source": "SPRING_CLOUD"
* },
* "uri": "http://192.168.6.239:8071",
* "scheme": null,
* "instanceId": null
* },
* {
* "serviceId": "user-service",
* "host": "192.168.6.239",
* "port": 8070,
* "secure": false,
* "metadata": {
* "nacos.instanceId": "192.168.6.239#8070#DEFAULT#DEFAULT_GROUP@@user-service",
* "nacos.weight": "1.0",
* "nacos.cluster": "DEFAULT",
* "nacos.healthy": "true",
* "preserved.register.source": "SPRING_CLOUD"
* },
* "uri": "http://192.168.6.239:8070",
* "scheme": null,
* "instanceId": null
* }
* ]
* @return
*/
@GetMapping(value = "/discovery")
public List<ServiceInstance> discovery() {
List<ServiceInstance> instances = discoveryClient.getInstances("user-service");
return instances;
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论