package com.sf.eurekaclientdemo1.feign; import com.sf.eurekaclientdemo1.dto.User; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.*; import java.util.Map; /** * 可以将要调用的服务名配置在当前的接口中 * eureka-client-supplier-demo * 再将要调用的接口名 配置在方法名之上 * * @GetMapping("/clientDemo2") 将一个要调用的微服务的一个接口 * 分别抽象为微服务对应类 * 接口对应方法 */ // http://eureka-client-supplier-demo // MyFeignClient 通过Feign 构造的Http客户端 // @FeignClient 可以把当前类注入到容器中 @FeignClient("eureka-client-supplier-demo") public interface MyFeignClient { // http://eureka-client-supplier-demo/clientDemo2 @GetMapping("/clientDemo2") String clientDemo2(); // String clientDemo2(); // http://eureka-client-supplier-demo/testId/111 @GetMapping("/testId/{id}") String testId(@PathVariable("id") String id); // http://eureka-client-supplier-demo/testId/111 @GetMapping("/testParam") String testParam(@RequestParam("param") String param); // http://eureka-client-supplier-demo/testUser // 错误的用法 @GetMapping("/testUser") String testUserError(User user); // http://eureka-client-supplier-demo/testUser // 正确的用法之一 我们可以通过不同的方法调用同一个接口 @GetMapping("/testUser") String testUser(@RequestParam("name") String name, @RequestParam("desc") String desc); // http://eureka-client-supplier-demo/testUser // 正确的用法之二 使用map传递参数 注意此时也必须有@RequestParam @GetMapping("/testUser") String testUser(@RequestParam Map map); // 计算的接口 @GetMapping("/randomInt") String randomInt(@RequestParam Map map); // 处理post请求 @PostMapping("/testPost") String testPost(@RequestBody User user); // 处理header // 如果使用注解时 没有明确属性名称 默认给value属性赋值 // 如果要给两个以上的属性赋值 value属性需要明确标识 @GetMapping(value = "/token", headers = {"token=123456"}) String token(); @GetMapping("/token") String token(@RequestHeader("token") String token); // 断路器相关 @GetMapping("/circuit/{id}") String circuit(@PathVariable("id") Integer id); // 链路追踪相关 @GetMapping("/micrometer/{id}") String micrometer(@PathVariable("id") Integer id); }