Skip to content

Commit 227020e

Browse files
committed
Add Client Timeout best practises in README
1 parent bb33558 commit 227020e

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,39 @@ System.setProperty("https.proxyUser", "squid");
346346
System.setProperty("https.proxyPassword", "ward");
347347
~~~~
348348

349+
### HTTP timeout configuration
350+
351+
The library provides configurable timeout settings on the `Config` object. These timeouts are applied consistently across all API calls (Checkout, Payments, Recurring, Terminal, etc.).
352+
353+
| Config Property | Default | Description |
354+
|------------------------------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
355+
| `connectionTimeoutMillis` | 60000 ms | Maximum time to wait for a TCP connection (and TLS handshake) to be established with the server. If the server is unreachable or slow to accept connections, this timeout fires. |
356+
| `readTimeoutMillis` | 60000 ms | Maximum time to wait for data on an already established connection (socket read timeout). This is the hard upper bound on how long any single API call can take once connected. |
357+
| `connectionRequestTimeoutMillis` | 60000 ms | Maximum time to wait to lease a connection from the internal connection pool. Relevant under high concurrency when the pool is saturated. |
358+
| `defaultKeepAliveMillis` | 60000 ms | Duration to keep idle connections alive for reuse. |
359+
360+
**Best practices:**
361+
362+
- Always set explicit timeouts for production environments. The 60-second defaults may be too high for latency-sensitive services.
363+
- Set `readTimeoutMillis` to match your maximum acceptable API response time. For example, if your SLA requires failing fast on slow downstream calls, use a lower value (e.g. 10-15 seconds).
364+
- Keep `connectionTimeoutMillis` relatively low (e.g. 5-15 seconds) since a healthy server should accept connections quickly.
365+
366+
~~~~ java
367+
// Example: Configure timeouts via Config object
368+
Config config = new Config()
369+
.environment(Environment.LIVE)
370+
.liveEndpointUrlPrefix("myCompany")
371+
.apiKey("YOUR_API_KEY")
372+
.connectionTimeoutMillis(10000) // 10 sec to establish connection
373+
.readTimeoutMillis(15000) // 15 sec max to receive a response
374+
.connectionRequestTimeoutMillis(5000); // 5 sec to acquire a pooled connection
375+
376+
Client client = new Client(config);
377+
378+
// Or use the convenience method on the Client object
379+
client.setTimeouts(10000, 15000);
380+
~~~~
381+
349382
### Client certificate authentication
350383

351384
~~~~ java

0 commit comments

Comments
 (0)