OpenFeign
一个声明式的WebService客户端,它能够让微服务之间的调用更加简单。使用的是接口和注解的方式。
官网的说明:
@Component
//value指的Eureka注册中心的服务名称
@FeignClient(value = "CLOUD-PROVIDER-PAYMENT800")
public interface PaymentFeignService {
@GetMapping("/payment/get/{id}")
CommonResult<Payment> QueryPaymentById(@PathVariable("id") Integer id);
}
@RestController
public class PaymentFeignController {
@Autowired
private PaymentFeignService paymentFeignService;
@GetMapping("/consumer/payment/get/{id}")
public CommonResult QueryPaymentById(@PathVariable("id") Integer id) {
CommonResult<Payment> paymentCommonResult = paymentFeignService.QueryPaymentById(id);
return paymentCommonResult;
}
}