1.创建一个springboot模块作为消费入口
@EnableDiscoveryClient
@SpringBootApplication
@EnableFeignClients
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
2.定义服务接口
@FeignClient("alibaba-nacos-discovery-server")
interface Client {
@GetMapping("/hello")
String hello(@RequestParam(name = "name") String name);
}
3.通过调用服务接口,实现远程调用
@Slf4j
@RestController
static class TestController {
@Autowired
Client client;
@GetMapping("/test")
public String test(@RequestParam("msg") String msg) {
String result = client.hello(msg);
return "消费者返回: " + result;
}
}
4.测试访问
![在这里插入图片描述](https://img-blog.csdnimg.cn/32dba70773944ed881c6432a679988a8.png)