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.
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.
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.
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.
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.