facebookarchive/swift

Need different set of API to register a hook to "Interface Proxy" to implement Retry and Load Balance

supercharger opened this issue · 2 comments

I couldn't find a API to register a hook so that a service method call can be retried, and Load balance among set of servers.

For ex:

 ExampleService client = thriftClient.open(connector).get();
 client.sayHello();

To handle sayHello method failure, and load balance.
There is no clean way to achieve do this, without writing boiler plate code at the application side or some library which works by having a Proxy around "Swift returned Proxy" to achieve it.

Any thoughts on this ?
I think we need a different Channel implementation than the current one.

@supercharger
what do you think about using this lib to provide some simple retrying feature:

private final Retryer retryer = RetryerBuilder.newBuilder()
        .retryIfException()
        .withWaitStrategy(WaitStrategies.fixedWait(1, TimeUnit.SECONDS))
        .withStopStrategy(StopStrategies.stopAfterAttempt(3))
        .build();
...
try {
    S service = new ThriftClient<>(clientManager, serviceClass, clientConfig, "thriftClient")
             .open(connector).get();
    return (T) retryer.call(() -> {
        return workFn.apply(service);
   });
} catch (ExecutionException | RetryException e) {
       throw new DataAccessException(e);
}