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:
        connectTimeout: 60000
        readTimeout: 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:
        connectTimeout: 10000
        readTimeout: 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.