spring-bootproxynetflixnetflix-feignnetflix-ribbon

Spring Cloud Feign/Ribbon with corporate proxy


I want to consume a REST service from the outside world behind a corporate proxy with authentication.

How do I configure Spring Boot + Spring Cloud Feign/Ribbon to use our proxy?


Solution

  • I believe you're looking for something like this:

    import feign.Feign;
    import okhttp3.OkHttpClient;
    import java.net.InetSocketAddress;
    import java.net.Proxy;
    ...
    Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy-url", 1234));
    OkHttpClient okHttpClient = new OkHttpClient.Builder().proxy(proxy).build();
    Feign.builder()
        .client(new feign.okhttp.OkHttpClient(okHttpClient))
        .target(...);
    

    You just have to additionally add compile 'io.github.openfeign:feign-okhttp:9.5.0' to your project.

    The target clause contains your defined Interface. Further reference: https://github.com/OpenFeign/feign