博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringCloud Feign使用二
阅读量:3726 次
发布时间:2019-05-22

本文共 2087 字,大约阅读时间需要 6 分钟。

SpringCloud Feign使用二

更多干货

一使用原生Feign注解

  • Feign默认使用的是 SpringMvc的注解,如果要使用Feign原生注解配置如下
@Configurationpublic class Configuration1 {  @Bean  public Contract feignContract() {    return new feign.Contract.Default();  }  //改变Feign 日志级别  @Bean  Logger.Level feignLoggerLevel() {    return Logger.Level.FULL;  }}
  • 指定使用配置Configuration1
import feign.Param;import feign.RequestLine;@FeignClient(name = "microservice-provider-user", configuration = Configuration1.class)public interface UserFeignClient {  @RequestLine("GET /simple/{id}")  public User findById(@Param("id") Long id);}

编写接口查询eureka接口信息

  • 指定eureka 的帐号信息
@Configurationpublic class Configuration2 {  @Bean  public BasicAuthRequestInterceptor basicAuthRequestInterceptor() {    return new BasicAuthRequestInterceptor("user", "password123");  }}
  • 可以指定请求的eureka 的 url
  • 指定配置文件 Configuration2
@FeignClient(name = "xxxx", url = "http://localhost:8761/", configuration = Configuration2.class)public interface FeignClient2 {  @RequestMapping(value = "/eureka/apps/{serviceName}")  public String findServiceInfoFromEurekaByServiceName(@PathVariable("serviceName") String serviceName);}

日志级别

logging:  level:    com.itmuch.cloud.feign.UserFeignClient: DEBUG

Feign 加入Ribbon 负载均衡

加入以下配置

microservice-provider-user:  ribbon:    NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule

Feign支持请求和响应的压缩

  • 增加gzip配置
#请求和响应GZIP压缩支持feign.compression.request.enabled=truefeign.compression.response.enabled=true

histrix

如果没有用到histrix则关闭

#Hystrix支持,如果为true,hystrix库必须在classpath中feign.hystrix.enabled=false

可修改融短器的超时时间

  • 修改长超时时间
  • timeout设置为false
  • 禁用掉hystrix
# hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 5000# 或者:# hystrix.command.default.execution.timeout.enabled: false# 或者:feign.hystrix.enabled: false ## 索性禁用feign的hystrix支持# 超时的issue:https://github.com/spring-cloud/spring-cloud-netflix/issues/768# 超时的解决方案: http://stackoverflow.com/questions/27375557/hystrix-command-fails-with-timed-out-and-no-fallback-available# hystrix配置: https://github.com/Netflix/Hystrix/wiki/Configuration#execution.isolation.thread.timeoutInMilliseconds

转载地址:http://kaonn.baihongyu.com/

你可能感兴趣的文章
ZZULIOJ----2618: ACM-ICPC亚洲区域赛ZZULI站
查看>>
Pseudoprime numbers(POJ-3641 快速幂)
查看>>
Piggy-Bank(HDU--1114)
查看>>
Strange fuction(HDU--2899)
查看>>
Hopscotch(POJ-3050)
查看>>
伊甸园日历游戏(vijos--1004)
查看>>
计算某年某月某日是星期几
查看>>
数字组合 (计蒜客 - T1218)
查看>>
程序设计:引爆炸弹 (计蒜客 - A1139)
查看>>
2020年第十一届蓝桥杯模拟赛解题报告
查看>>
Mysql单表查询的基本操作
查看>>
Mysql基本操作
查看>>
Mysql单表查询例题详解
查看>>
java——安装JDK及配置解决常见问题
查看>>
java类、封装、继承
查看>>
数据库程序设计(毕业选题系统)
查看>>
算法(分治、贪心、dp、回溯、分支限界)总结
查看>>
Java数据类型
查看>>
Jungle Roads(最小生成树)
查看>>
最短路径问题(HDU3790)
查看>>