eureka:
client:
serviceUrl:
defaultZone: http://localhost:8801/eureka/
server:
port: 8802
spring:
application:
name: ribbon-producer
@Bean
@LoadBalanced
public RestTemplate restTemplate(){
return new RestTemplate();
}
@RestController
public class HelloController {
@Autowired
private HelloService helloService;
@GetMapping("/hello")
@Service
public class HelloService {
public String sayHello(){
return "HelloWorld"; // 提供一个hello World
}
}
@RestController
public class HelloController {
@Autowired
private HelloService helloService;
@GetMapping("/hello")
public String sayHello(String name){
return helloService.sayHello() + " " + name;
}
}
@Service
public class HelloService {
@Autowired
private RestTemplate restTemplate;
public String sayHello(){
return restTemplate.getForObject("http://ribbon-producer/hello?name=ribbon-consumer to",String.class);// 向server-id为“ribbon-producer”的服务器发送调用请求
}
}
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8801/eureka/
server:
port: 8803
spring:
application:
name: ribbon-consumer
@FeignClient(value = "ribbon-consumer")
public interface GetHello {
@RequestMapping(value = "/hello?name=feign-consumer to",method = RequestMethod.GET)
public String sayHello();
}
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8801/eureka/
server:
port: 8804
spring:
application:
name: feign-consumer