use of com.netflix.client.RetryHandler in project ribbon by Netflix.
the class LoadBalancerContext method noteResponse.
/**
* This is called after a response is received from the client
* to update related stats.
*/
protected void noteResponse(ServerStats stats, ClientRequest request, Object response, long responseTime) {
if (stats == null) {
return;
}
try {
recordStats(stats, responseTime);
RetryHandler errorHandler = getRetryHandler();
if (errorHandler != null && response != null) {
stats.clearSuccessiveConnectionFailureCount();
}
} catch (Exception ex) {
logger.error("Error noting stats for client {}", clientName, ex);
}
}
use of com.netflix.client.RetryHandler in project ribbon by Netflix.
the class LoadBalancerContext method noteRequestCompletion.
/**
* This is called after a response is received or an exception is thrown from the client
* to update related stats.
*/
public void noteRequestCompletion(ServerStats stats, Object response, Throwable e, long responseTime, RetryHandler errorHandler) {
if (stats == null) {
return;
}
try {
recordStats(stats, responseTime);
RetryHandler callErrorHandler = errorHandler == null ? getRetryHandler() : errorHandler;
if (callErrorHandler != null && response != null) {
stats.clearSuccessiveConnectionFailureCount();
} else if (callErrorHandler != null && e != null) {
if (callErrorHandler.isCircuitTrippingException(e)) {
stats.incrementSuccessiveConnectionFailureCount();
stats.addToFailureCount();
} else {
stats.clearSuccessiveConnectionFailureCount();
}
}
} catch (Exception ex) {
logger.error("Error noting stats for client {}", clientName, ex);
}
}
use of com.netflix.client.RetryHandler in project feign-reactive by kptfh.
the class LoadBalancingReactiveHttpClientTest method loadBalancingWithRetry.
private void loadBalancingWithRetry(int failedAttemptsNo, int retryOnSame, int retryOnNext) throws IOException, InterruptedException {
String body = "success!";
Stream.of(server1, server2).forEach(server -> {
mockSuccessAfterSeveralAttempts(server, "/", failedAttemptsNo, 503, aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(body));
});
String serverListKey = serviceName + ".ribbon.listOfServers";
getConfigInstance().setProperty(serverListKey, "localhost:" + server1.port() + "," + "localhost:" + server2.port());
RetryHandler retryHandler = new RequestSpecificRetryHandler(true, true, new DefaultLoadBalancerRetryHandler(retryOnSame, retryOnNext, true), null);
TestInterface client = CloudReactiveFeign.<TestInterface>builder().webClient(WebClient.create()).setLoadBalancerCommand(LoadBalancerCommand.builder().withLoadBalancer(AbstractLoadBalancer.class.cast(getNamedLoadBalancer(serviceName))).withRetryHandler(retryHandler).build()).target(TestInterface.class, "http://" + serviceName);
try {
String result = client.get().block();
assertThat(result).isEqualTo(body);
} finally {
getConfigInstance().clearProperty(serverListKey);
}
}
use of com.netflix.client.RetryHandler in project ribbon by Netflix.
the class LoadBalancerContext method noteError.
/**
* This is called after an error is thrown from the client
* to update related stats.
*/
protected void noteError(ServerStats stats, ClientRequest request, Throwable e, long responseTime) {
if (stats == null) {
return;
}
try {
recordStats(stats, responseTime);
RetryHandler errorHandler = getRetryHandler();
if (errorHandler != null && e != null) {
if (errorHandler.isCircuitTrippingException(e)) {
stats.incrementSuccessiveConnectionFailureCount();
stats.addToFailureCount();
} else {
stats.clearSuccessiveConnectionFailureCount();
}
}
} catch (Exception ex) {
logger.error("Error noting stats for client {}", clientName, ex);
}
}
use of com.netflix.client.RetryHandler in project ribbon by Netflix.
the class LoadBalancerCommandTest method testRetrySameServer.
@Test
public void testRetrySameServer() {
BaseLoadBalancer loadBalancer = LoadBalancerBuilder.newBuilder().buildFixedServerListLoadBalancer(list);
RetryHandler handler = new RetryHandler() {
@Override
public boolean isRetriableException(Throwable e, boolean sameServer) {
return (e instanceof IllegalArgumentException);
}
@Override
public boolean isCircuitTrippingException(Throwable e) {
return false;
}
@Override
public int getMaxRetriesOnSameServer() {
return 3;
}
@Override
public int getMaxRetriesOnNextServer() {
return 0;
}
};
LoadBalancerCommand<String> command = LoadBalancerCommand.<String>builder().withLoadBalancer(loadBalancer).withRetryHandler(handler).withServer(server1).build();
ServerOperation<String> operation = new ServerOperation<String>() {
AtomicInteger count = new AtomicInteger();
@Override
public Observable<String> call(final Server server) {
return Observable.create(new OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> t1) {
if (count.incrementAndGet() < 3) {
t1.onError(new IllegalArgumentException());
} else {
t1.onNext(server.getHost());
t1.onCompleted();
}
}
});
}
};
String result = command.submit(operation).toBlocking().single();
assertEquals(3, loadBalancer.getLoadBalancerStats().getSingleServerStat(server1).getTotalRequestsCount());
assertEquals("1", result);
}
Aggregations