netflix-feign

can @FeignClient extend - and @RestController implement - a common, fully-annotated Interface?

浪尽此生 提交于 2020-01-06 20:17:43
问题 I want a Feign client to consume a Spring Boot controller, and I want the contract between them to be specified in a common Interface to the degree possible. The interface with method would look something like this: @RequestMapping public interface RuleManager { @RequestMapping(value = "/addRule", method = RequestMethod.POST, consumes = {"application/json"}, produces = {"application/json"}) @ResponseBody Rule addRule(@RequestBody Rule rule); } The Feign client would look like: @FeignClient

Feign builder timeouts not working

旧时模样 提交于 2020-01-02 10:00:50
问题 We are using Netflix feign to connect to a downstream client, but our request.options connect and read timeouts are not working. This is how we are passing parameters to the builder Feign.builder() .client(new OkHttpClient(okHttpClient)) .encoder(new GsonEncoder()) .decoder(new GsonDecoder()) .options(new Request.Options(connectTimeoutInMS, readTimeoutInMs) .target(*,*); We have set readTimeout and ConnectionTimeout to 1 sec. But what we see is even when the target takes more than 1 sec to

Netflix Feign - Propagate Status and Exception through Microservices

本小妞迷上赌 提交于 2020-01-01 03:58:06
问题 I'm using Netflix Feign to call to one operation of a Microservice A to other other operation of a Microservice B which validates a code using Spring Boot. The operation of Microservice B throws an exception in case of the validation has been bad. Then I handled in the Microservices and return a HttpStatus.UNPROCESSABLE_ENTITY (422) like next: @ExceptionHandler({ ValidateException.class }) @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY) @ResponseBody public Object validationException(final

How to Set Request Headers Using a Feign Client?

两盒软妹~` 提交于 2020-01-01 03:29:12
问题 We are developing a suite of Microservices using Spring Cloud framework and one of the the things that we need to do is to set request headers. I know I can pass a parameter @RequestHeader to a Feign method but the value needs to come from another bean. I don't know if SPEL can be used for a Feign param value. I was thinking that this is a common enough use case for most clients so there'd be some examples, but so far I've not found any. Of course I can dig through the Spring course code and

Feign + Ribbon request interception AFTER target host is choosen

核能气质少年 提交于 2019-12-24 02:07:22
问题 What I'm currently doing (which is very simple and convenient way): Feign.builder() .client(RibbonClient.create()) ... .requestInterceptor(new MyInterceptor()) But interception occur before ribbon actually resolve target host. Problem is, that one header that I want to add, have to be created based on the name of the target host. Is there anyway I can manipulate headers after host is resolved? 回答1: I have found following solution for this problem. Instead of using Feign interceptor I use

Using @RequestLine with Feign

妖精的绣舞 提交于 2019-12-20 12:26:53
问题 I have a working Feign interface defined as: @FeignClient("content-link-service") public interface ContentLinkServiceClient { @RequestMapping(method = RequestMethod.GET, value = "/{trackid}/links") List<Link> getLinksForTrack(@PathVariable("trackid") Long trackId); } If I change this to use @RequestLine @FeignClient("content-link-service") public interface ContentLinkServiceClient { @RequestLine("GET /{trackid}/links") List<Link> getLinksForTrack(@Param("trackid") Long trackId); } I get the

How to custom @FeignClient Expander to convert param?

本秂侑毒 提交于 2019-12-20 02:54:59
问题 Feign default expander to convert param: final class ToStringExpander implements Expander { @Override public String expand(Object value) { return value.toString(); } } I want custom it to convert user to support GET param, like this @FeignClient("xx") interface UserService{ @RequestMapping(value="/users",method=GET) public List<User> findBy(@ModelAttribute User user); } userService.findBy(user); What can i do? 回答1: First,you must write a expander like ToJsonExpander : public class

Can a Spring Cloud Feign client share interface with an Spring Web Controller?

时间秒杀一切 提交于 2019-12-17 22:42:52
问题 Building an endpoint and client with Spring MVC and Feign Client (with spring cloud). I had the thought that since both ends need to have the same annotations - and that they have to be pretty much in sync. Maybe I could define them in an interface and have the two ends implement that. Testing it out I was somewhat surprised that it actually works for the Spring Web end. But it I cannot find a way to do the same for a Feign client. I basically have the interface: @RequestMapping("/somebaseurl

How to use OpenFeign to get a pojo array?

孤街醉人 提交于 2019-12-13 02:17:11
问题 I’m trying to use a OpenFeign client to hit an API, get some JSON, and convert it to a POJO array. Previously I was simply getting a string of JSON and using Gson to convert it to the array like so FeignInterface { String get(Request req); } String json = feignClient.get(request); POJO[] pojoArray = new Gson().fromJson(json, POJO[].class); This was working. I would like to eliminate the extra step and have feign auto decode the JSON and return a POJO directly though, so I am trying this

'Too many body parameters' Exception on Feign Client

旧巷老猫 提交于 2019-12-12 14:22:12
问题 I am using Springs Feign Client functionality to communicate from one micro service to another. Now, the called service exposes a REST interface which accepts a file and a related (JSON)Object. @RequestMapping(value = {CONVERT_PATH, APPLICATION_PATH + CONVERT_PATH}, method = RequestMethod.POST, produces = CONTENT_TYPE) public ResponseEntity<InputStreamResource> convert(@RequestPart("file") MultipartFile file, @RequestParam("input") Input in) {...} This interface is functioning fine, I have