public class RetryExecutor extends Object
Here is an example, how to use this class for a reliable webhooks subscription when a microservice starts:
@Singleton
public class WebhooksSubscriber implements Managed {
private final RetryExecutor retryExecutor;
@Inject
public WebhooksSubscriber(AppConfiguration appConfiguration) {
this.retryExecutor = new RetryExecutor();
}
protected void upsertSubscription(Subscription subscription) {
retryExecutor.run((attemptCount) -> {
try {
Subscription existingSubscription = getSubscriptions(null, subscription.getIdentifier());
if (existingSubscription == null) {
LOG.info("creating new webhooks subscription '{}'", subscription);
subscriptionsApi.createSubscription(subscription);
} else {
LOG.debug("refreshing webhooks subscription '{}'", subscription);
subscriptionsApi.updateSubscription(existingSubscription.getId(), subscription);
}
} catch (ApiException e) {
LOG.info("Could not subscribe to webhooks with attempt {}", attemptCount, e);
throw e;
}
});
}
@Override
public void stop() throws Exception {
retryExecutor.stop();
}
...
}
| Modifier and Type | Class and Description |
|---|---|
static class |
RetryExecutor.ExpectedFailureException |
static interface |
RetryExecutor.RetryTask |
| Constructor and Description |
|---|
RetryExecutor() |
RetryExecutor(int corePoolSize,
int delayAfterFail,
TimeUnit delayAfterFailUnit,
String patternThreadFactory) |
public void stop()
throws InterruptedException
InterruptedExceptionpublic void run(RetryExecutor.RetryTask task)
Copyright © 2020 LeanIX GmbH. All rights reserved.