Generic Top

I just announced the new Learn Spring course, focused on the fundamentals of Spring 5 and Spring Boot 2:

>> CHECK OUT THE COURSE

1. Introduction

Spring Cloud Feign Client is a handy declarative REST client, that we use to implement communication between microservices.

In this short tutorial, we'll show how to set a custom Feign Client connection timeout, both globally and per client.

2. Defaults

Feign Client is pretty configurable.

In terms of a timeout, it allows us to configure both read and connection timeouts. Connection timeout is the time needed for the TCP handshake, while the read timeout needed to read data from the socket.

Connection and read timeouts are by default 10 and 60 seconds, respectively.

3. Globally

We can set the connection and read timeouts that apply to every Feign Client in the application via the feign.client.config.default property set in our application.yml file:

feign:
  client:
    config:
      default:
        connect-timeout: 60000
        read-timeout: 10000

The values represent the number of milliseconds before a timeout occurs.

4. Per-client

It's also possible to set these timeouts per specific client by naming the client:

feign:
  client:
    config:
      FooClient:
        connect-timeout: 10000
        read-timeout: 20000

And, we could, of course, list a global setting and also per-client overrides together without a problem.

5. Conclusion

In this tutorial, we explained how to tweak Feign Client's timeouts and how to set custom values through the application.yml file. Feel free to try these out by following our main Feign introduction.

Generic bottom

I just announced the new Learn Spring course, focused on the fundamentals of Spring 5 and Spring Boot 2:

>> CHECK OUT THE COURSE
Comments are closed on this article!