mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
add discovery example
This commit is contained in:
parent
ae4f1bf8a2
commit
a589af30e1
@ -2,6 +2,7 @@ package org.springframework.cloud.alibaba.cloud.examples;
|
|||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cloud.alibaba.cloud.examples.ConsumerApplication.EchoService;
|
import org.springframework.cloud.alibaba.cloud.examples.ConsumerApplication.EchoService;
|
||||||
|
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
@ -19,6 +20,10 @@ public class TestController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private EchoService echoService;
|
private EchoService echoService;
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DiscoveryClient discoveryClient;
|
||||||
|
|
||||||
@RequestMapping(value = "/echo-rest/{str}", method = RequestMethod.GET)
|
@RequestMapping(value = "/echo-rest/{str}", method = RequestMethod.GET)
|
||||||
public String rest(@PathVariable String str) {
|
public String rest(@PathVariable String str) {
|
||||||
return restTemplate.getForObject("http://service-provider/echo/" + str, String.class);
|
return restTemplate.getForObject("http://service-provider/echo/" + str, String.class);
|
||||||
@ -27,4 +32,14 @@ public class TestController {
|
|||||||
public String feign(@PathVariable String str) {
|
public String feign(@PathVariable String str) {
|
||||||
return echoService.echo(str);
|
return echoService.echo(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(value="/client",method = RequestMethod.GET)
|
||||||
|
public Object client(){
|
||||||
|
return discoveryClient.getInstances("service-consumer");
|
||||||
|
}
|
||||||
|
@RequestMapping(value="/services",method = RequestMethod.GET)
|
||||||
|
public Object services(){
|
||||||
|
return discoveryClient.getServices();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user