码迷,mamicode.com
首页 > 其他好文 > 详细

Feign 服务间的调用

时间:2020-03-25 14:57:37      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:red   wired   restful   cloud   discovery   websocket   spring   jaxrs   find   

Feign是简化Java HTTP客户端开发的工具(java-to-httpclient-binder),它的灵感来自于Retrofit、JAXRS-2.0和WebSocket。Feign的初衷是降低统一绑定Denominator到HTTP API的复杂度,不区分是否为restful。
 
添加依赖 
<dependency> 
    <groupId>org.springframework.cloud</groupId> 
    <artifactId>spring‐cloud‐starter‐openfeign</artifactId> 
</dependency>

启动类添加注解 

  @EnableDiscoveryClient

   @EnableFeignClients

创建client包 

  创建接口 

@FeignClient("API‐base") //从哪个服务中调用功能 ,注意 里面的名称与被调用的服务名保持一致,并且不能包含下划线
public interface LabelClient {
@RequestMapping(value="/test/{id}", method = RequestMethod.GET) //@RequestMapping注解用于对被调用的微服务进行地址映射。注意 @PathVariable注解一定要指定参数名称,否则出错
public Result findById(@PathVariable("id") String id); }

调用 

@Autowired 
private LabelClient labelClient; 
@RequestMapping(value
= "/test/{testid}") public Result findById(@PathVariable String testid){   Result result = labelClient.findById(labelid);
  return result;
}

feign集成了负载均衡 

 

 

 

Feign 服务间的调用

标签:red   wired   restful   cloud   discovery   websocket   spring   jaxrs   find   

原文地址:https://www.cnblogs.com/qin1993/p/12566225.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!