Feign

How to fine-tune the Spring Cloud Feign client?

雨燕双飞 提交于 2019-12-04 09:07:51
The Spring Cloud doc says: If Hystrix is on the classpath, by default Feign will wrap all methods with a circuit breaker. That's good but how do I configure the Hystrix options to ignore certain exceptions? I've an ErrorDecoder implementation that maps HTTP status code to exceptions. If I put @HystrixCommand on the method, does Feign honor that? Our requirement is to log various details about every HTTP call made out to dependencies. Currently I've a decorated RestTemplate that does this. From what I see in the code and based on Dave Syer's answer here , Feign does't use a RestTemplate . So

@EnableFeignClients and @FeignClient fail on Autowiring 'FeignContext' NoSuchBeanException

随声附和 提交于 2019-12-04 02:36:18
The microservice I'm writting needs to communicate to other microservices in our platform. On that attempt, the ideal solution for us is Spring Cloud Netflix Feign , implemeting a @FeignClient . However, I'm facing the exception below when I try an @Autowired ReviewProvider : Exception (cause) Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.netflix.feign.FeignContext' available at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:353) at org

File upload spring cloud feign client

感情迁移 提交于 2019-12-03 21:48:28
When make a post request from one microservice to another using feign client of spring cloud netflix, I get the following error in Postman : { "timestamp": 1506933777413, "status": 500, "error": "Internal Server Error", "exception": "feign.codec.EncodeException", "message": "Could not write JSON: No serializer found for class java.io.FileDescriptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.io

How to add a request interceptor to a feign client?

ぃ、小莉子 提交于 2019-12-03 12:35:03
问题 I want every time when I make a request through feign client, to set a specific header with my authenticated user. This is my filter from which I get the authentication and set it to the spring security context: @EnableEurekaClient @SpringBootApplication @EnableFeignClients public class PerformanceApplication { @Bean public Filter requestDetailsFilter() { return new RequestDetailsFilter(); } public static void main(String[] args) { SpringApplication.run(PerformanceApplication.class, args); }

How to add a request interceptor to a feign client?

半腔热情 提交于 2019-12-03 06:43:32
I want every time when I make a request through feign client, to set a specific header with my authenticated user. This is my filter from which I get the authentication and set it to the spring security context: @EnableEurekaClient @SpringBootApplication @EnableFeignClients public class PerformanceApplication { @Bean public Filter requestDetailsFilter() { return new RequestDetailsFilter(); } public static void main(String[] args) { SpringApplication.run(PerformanceApplication.class, args); } private class RequestDetailsFilter implements Filter { @Override public void init(FilterConfig

[Spring Cloud] 4.6 Declarative REST Client:Feign

偶尔善良 提交于 2019-12-02 06:24:59
4.6 Declarative REST Client: Feign REST客户端:Feign Feign 是一个Web服务的客户端框架。它让Web服务的客户端开发变得更容易。 只需要使用Feign创建一个接口加上一个注解就行了。Feign和JAX-RS提供一整套插件化的注解配置方式。在Feign中还可以使用插件化的编码器和解码器。 Spring Cloud 还提供一个 HttpMessageConverters ,这样当使用Spring Web环境时,就可以支持Spring MVC。 在使用Feign时,Spring Cloud还可以整合Ribbon和Eureka,为http客户端提供负载均衡的能力。 4.6.1 How to Include Feign 如何引入Feign 在工程中引入Feign只需要引入依赖就行:group : org.springframework.cloud artifact id : spring-cloud-starter-feign 。详情见 Spring Cloud相关文档 例如: @Configuration @ComponentScan @EnableAutoConfiguration @EnableEurekaClient @EnableFeignClients public class Application { public

SpringBoot: FeignClient with SSL (p12)

谁说我不能喝 提交于 2019-12-01 20:51:57
问题 I'm trying to create a FeignClient for one external HTTP API which uses SSL. The struggle is - how to modify default Spring FeignClient with my logic, in this case SSL Connection Factory. So basically I wanna keep all the good things Spring automatically does for the FeignClients, like Hystrix, Sleuth tracing, etc and make it work with my SSL factory. Will appreciate any suggestions. Here is what I tried to do: I've tried to provide a custom @Configuration outside of ComponentScan:

feign Method has too many Body parameters

不羁的心 提交于 2019-12-01 02:12:43
1、feign多参数问题 1.1GET方式 错误写法 @RequestMapping(value="/test", method=RequestMethod.GET) Model test(final String name, final int age); 启动服务的时候,会报如下异常: Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract com.chhliu.springboot.restful.vo.User com.chhliu.springboot.restful.feignclient.UserFeignClient.findByUsername(java.lang.String,java.lang.String) 异常原因:当使用Feign时,如果发送的是get请求,那么需要在请求参数前加上@RequestParam注解修饰,Controller里面可以不加该注解修饰。 正确写法 @RequestMapping(value="/test", method=RequestMethod.GET) Model test(@RequestParam("name") final String name,@RequestParam("age

Spring Cloud学习:02服务消费者(Ribbon&Feign)

旧街凉风 提交于 2019-11-30 02:52:04
在微服务架构中,业务会拆分成一个独立的服务,服务与服务之间基于http restful进行通信。Spring Cloud有两种服务调用方式,一种是Ribbon+restTemplate,另一种是Feign。 1 Ribbon+restTemplate 1.1 Ribbon介绍 Spring Cloud Ribbon是基于HTTP和TCP的客户端负载均衡工具,基于Netflix Ribbon实现。通过Spring Cloud封装,可以方便地将面向服务的REST模板请求自动转换成客户端负载均衡的服务调用。包括下面的Feign调用,也是基于Ribbon实现的。 基于Spring Cloud Ribbon的封装,使用客户端负载均衡调用服务非常简单,只需实现两步: ①服务提供者只需启动多个服务实例并注册到一个注册中心或多个相关联的服务注册中心。 ②服务消费者直接通过调用被@LoadBalanced注解(开启客户端负载均衡)的RestTemplate实现面向服务的接口调用。 1.2 测试Ribbon+restTemplate方式调用 1.2.1创建服务提供方(Eureka Client) 基于之前工程,创建新模块ribbon-service,选择Spring Initializr->Cloud Discovery->Eureka Discovery,并添加以下依赖: <dependencies

Spring Cloud中Feign的常见问题

流过昼夜 提交于 2019-11-28 23:08:59
一、FeignClient接口,不能使用@GettingMapping 之类的组合注解 @FeignClient("microservice-provider-user") public interface UserFeignClient { @RequestMapping(value = "/simple/{id}", method = RequestMethod.GET) public User findById(@PathVariable("id") Long id); ... } 这边的 @RequestMapping(value = "/simple/{id}", method = RequestMethod.GET) 不能写成 @GetMapping("/simple/{id}") 。 二、FeignClient接口中,如果使用到@PathVariable ,必须指定其value @FeignClient("microservice-provider-user") public interface UserFeignClient { @RequestMapping(value = "/simple/{id}", method = RequestMethod.GET) public User findById(@PathVariable("id") Long id); .