Skip to content

Commit 3d30c6d

Browse files
committed
Update retrying client documentation
Update retrying client documentation according to our new documentation policy Closes #309
1 parent 259fcfd commit 3d30c6d

File tree

1 file changed

+14
-35
lines changed

1 file changed

+14
-35
lines changed

docs/RetryingTarantoolClient.md

+14-35
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,17 @@ By default, failed requests will be repeated only for some known network problem
1111
Some retry policies are available in the `TarantoolRequestRetryPolicies` class, but you may use your own implementations.
1212
If you want to use proxy calls or retry settings only for a number of requests, you may use configureClient(client)
1313
in `TarantoolClientFactory` for making a new configured client instance. Note, that the new instance will share the same
14-
connection pool and basic client settings, and only augment the behavior of the client.
15-
See an example below:
16-
17-
```java
18-
19-
TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> setupClient() {
20-
return TarantoolClientFactory.createClient()
21-
.withCredentials("admin", "secret-cluster-cookie")
22-
.withAddress(container.getRouterHost(), container.getRouterPort())
23-
.withProxyMethodMapping()
24-
.build();
25-
}
26-
27-
TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> retrying(
28-
TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> client, int retries, long delay) {
29-
return TarantoolClientFactory.configureClient(client)
30-
.withRetryingByNumberOfAttempts(
31-
retries,
32-
// you can use default predicates from TarantoolRequestRetryPolicies for checking errors
33-
TarantoolRequestRetryPolicies.retryNetworkErrors()
34-
// also you can use your own predicates and combine them with each other or with defaults
35-
.or(e -> e.getMessage().contains("Unsuccessful attempt"))
36-
.or(TarantoolRequestRetryPolicies.retryTarantoolNoSuchProcedureErrors()),
37-
policy -> policy.withDelay(delay))
38-
.build();
39-
}
40-
41-
...
42-
43-
TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> client = setupClient();
44-
String result = retrying(client, 4, 500).callForSingleResult("retrying_function", String.class).get();
45-
assertEquals("Success", result);
46-
result = retrying(client, 2, 1000).callForSingleResult("retrying_function", String.class).get();
47-
assertEquals("Success", result);
48-
```
14+
connection pool and basic client settings, and only augment the behavior of the client.
15+
16+
In this example I use custom delete function.
17+
https://github.com/tarantool/cartridge-java/blob/cb018c6ded848255637f12ef33d67cec6a019be5/src/test/resources/cartridge/app/roles/api_router.lua#L165-L176
18+
You can set up any client. In this case I use CRUD client.
19+
https://github.com/tarantool/cartridge-java/blob/cb018c6ded848255637f12ef33d67cec6a019be5/src/test/java/io/tarantool/driver/integration/ReconnectIT.java#L147-L163
20+
And reuse it then I need retrying client.
21+
https://github.com/tarantool/cartridge-java/blob/cb018c6ded848255637f12ef33d67cec6a019be5/src/test/java/io/tarantool/driver/integration/ReconnectIT.java#L194-L214
22+
You don't have to set up basic client if you need retying client only.
23+
All methods of client builder with prefix `withRetrying` can be used with `createClient`.
24+
25+
In this code I call `delete_with_error_if_not_found` (custom delete function) before the record was inserted to the
26+
database. So client recalls delete and removes the record after it was inserted.
27+
https://github.com/tarantool/cartridge-java/blob/cb018c6ded848255637f12ef33d67cec6a019be5/src/test/java/io/tarantool/driver/integration/ReconnectIT.java#L82-L109

0 commit comments

Comments
 (0)