本文共 2087 字,大约阅读时间需要 6 分钟。
@Configurationpublic class Configuration1 { @Bean public Contract feignContract() { return new feign.Contract.Default(); } //改变Feign 日志级别 @Bean Logger.Level feignLoggerLevel() { return Logger.Level.FULL; }}
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);}
@Configurationpublic class Configuration2 { @Bean public BasicAuthRequestInterceptor basicAuthRequestInterceptor() { return new BasicAuthRequestInterceptor("user", "password123"); }}
@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
加入以下配置
microservice-provider-user: ribbon: NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule
#请求和响应GZIP压缩支持feign.compression.request.enabled=truefeign.compression.response.enabled=true
如果没有用到histrix则关闭
#Hystrix支持,如果为true,hystrix库必须在classpath中feign.hystrix.enabled=false
可修改融短器的超时时间
# 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/