关于微服务RPC远程调用,之前已经简单介绍过feign以及openfeign,并且就参数传递与接收也进行过简单讲解。
Nacos+Feign简单使用:https://blog.csdn.net/u011177064/article/details/104309921
本文继续介绍feign采用实体对象作为请求响应参数具体怎么使用。
以下是几种常见的用法:
1、
请求参数: GET请求,请求参数按字段名使用@RequestParam注解,并且里面的 value 必须和 服务生产者的参数名一致
响应参数: 实体+泛型
消费者-请求
//表示该接口的方法由feign实现远程调用,
//目标接口地址示例: jfcloud-mall-storage/storage/getStorages
@FeignClient(name = "jfcloud-mall-storage") //jfcloud-mall-storage在nacos中已注册
public interface StorageServiceClient {
@GetMapping(path = "/storage/getStorages")
public RespDataT<List<JfcloudStorage>> getStoragesByEntity(@RequestParam("productIds") Long[] productIds);
}