Commit 2010dd3d authored by duanledexianxianxian's avatar duanledexianxianxian 😁

add 服务注册与服务发现

parent 66b8deb1
Pipeline #97 failed
...@@ -2,6 +2,7 @@ package com.duanledexian.spring.cloud.producer.api; ...@@ -2,6 +2,7 @@ package com.duanledexian.spring.cloud.producer.api;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
/** /**
* The interface Hello api. * The interface Hello api.
...@@ -18,6 +19,6 @@ public interface IHelloApi { ...@@ -18,6 +19,6 @@ public interface IHelloApi {
* @return the string * @return the string
*/ */
@GetMapping("/api/v1/sayHello") @GetMapping("/api/v1/sayHello")
String sayHello(String name); String sayHello(@RequestParam("name") String name);
} }
...@@ -27,7 +27,7 @@ public class HomeController { ...@@ -27,7 +27,7 @@ public class HomeController {
@GetMapping("/sayHello") @GetMapping("/sayHello")
public String sayHello(String name) { public String sayHello(String name) {
name += "!"; name += "!";
ServiceInstance instance = client.choose("service-consumer"); ServiceInstance instance = client.choose("service-producer");
String url = "http://" + instance.getHost() + ":" + instance.getPort() + "/api/v1/sayHello?name=" + name; String url = "http://" + instance.getHost() + ":" + instance.getPort() + "/api/v1/sayHello?name=" + name;
return restTemplate.getForObject(url, String.class); return restTemplate.getForObject(url, String.class);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment