I am trying to connect to a remote websocket endpoint (inside spring boot app), and if it throws an Exception I use resilience4j-retry v1.7.7 with JDK 8 to retry connection. However resilience4j-retry tries to connect once and if it fails do not retry. What have I done wrong, the connection is called on ApplicationReadyEvent
.
@Autowired
private WsConnector connector;
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
RetryConfig config = RetryConfig.custom()
.maxAttempts(5)
.waitDuration(Duration.ofSeconds(5))
.build();
RetryRegistry registry = RetryRegistry.of(config);
Retry retry = registry.retry("retryableSupplier", config);
CheckedFunction0<String> retryableSupplier = Retry.decorateCheckedSupplier(retry, connector::startConnection);
try {
System.out.println("retrying " + retryableSupplier.apply());
} catch (Throwable throwable) {
throwable.printStackTrace();
}
Retry.EventPublisher publisher = retry.getEventPublisher();
publisher.onRetry(event1 -> System.out.println(event1.toString()));
publisher.onSuccess(event2 -> System.out.println(event2.toString()));
}
@Service
public class WsConnector {
public String startConnection() throws Exception {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
WSClient client = new WSClient();
container.connectToServer(client, new URI("ws://viewpoint:8080/ping"));
return "Connected";
}
}