Skip to content

Commit

Permalink
Update retrying client documentation
Browse files Browse the repository at this point in the history
Update retrying client documentation according to our new documentation policy

Closes #309
  • Loading branch information
iDneprov committed Feb 6, 2023
1 parent 1e8eea5 commit 85726ca
Showing 1 changed file with 11 additions and 35 deletions.
46 changes: 11 additions & 35 deletions docs/RetryingTarantoolClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,14 @@ By default, failed requests will be repeated only for some known network problem
Some retry policies are available in the `TarantoolRequestRetryPolicies` class, but you may use your own implementations.
If you want to use proxy calls or retry settings only for a number of requests, you may use configureClient(client)
in `TarantoolClientFactory` for making a new configured client instance. Note, that the new instance will share the same
connection pool and basic client settings, and only augment the behavior of the client.
See an example below:

```java

TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> setupClient() {
return TarantoolClientFactory.createClient()
.withCredentials("admin", "secret-cluster-cookie")
.withAddress(container.getRouterHost(), container.getRouterPort())
.withProxyMethodMapping()
.build();
}

TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> retrying(
TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> client, int retries, long delay) {
return TarantoolClientFactory.configureClient(client)
.withRetryingByNumberOfAttempts(
retries,
// you can use default predicates from TarantoolRequestRetryPolicies for checking errors
TarantoolRequestRetryPolicies.retryNetworkErrors()
// also you can use your own predicates and combine them with each other or with defaults
.or(e -> e.getMessage().contains("Unsuccessful attempt"))
.or(TarantoolRequestRetryPolicies.retryTarantoolNoSuchProcedureErrors()),
policy -> policy.withDelay(delay))
.build();
}

...

TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> client = setupClient();
String result = retrying(client, 4, 500).callForSingleResult("retrying_function", String.class).get();
assertEquals("Success", result);
result = retrying(client, 2, 1000).callForSingleResult("retrying_function", String.class).get();
assertEquals("Success", result);
```
connection pool and basic client settings, and only augment the behavior of the client.

You can set up basic client
https://github.com/tarantool/cartridge-java/blob/ba5602651a89132ead5f33f00a1a4462bce117d0/src/test/java/io/tarantool/driver/integration/ReconnectIT.java#L109-L123
And reuse it then you need retrying client
https://github.com/tarantool/cartridge-java/blob/ba5602651a89132ead5f33f00a1a4462bce117d0/src/test/java/io/tarantool/driver/integration/ReconnectIT.java#L153-L171
But you don't have to set up basic client if you need retying client only.
All methods of client builder with prefix `withRetrying` can be used with `createClient`.

And example of client API usage if you specify using the default CRUD proxy operations mapping configuration
https://github.com/tarantool/cartridge-java/blob/8a880423da1ce2bc0e82557d70ab46c9e7eba618/src/test/java/io/tarantool/driver/integration/ProxyTarantoolClientExampleIT.java#L64-L107

0 comments on commit 85726ca

Please sign in to comment.