co.com.bancolombia.commons.jms.utils.RetryableTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-jms-utils Show documentation
Show all versions of commons-jms-utils Show documentation
A performant abstraction on top of JMS
The newest version!
package co.com.bancolombia.commons.jms.utils;
import co.com.bancolombia.commons.jms.internal.models.RetryableConfig;
import io.github.resilience4j.core.IntervalFunction;
import io.github.resilience4j.retry.Retry;
import io.github.resilience4j.retry.RetryConfig;
import lombok.experimental.UtilityClass;
@UtilityClass
public class RetryableTask {
public static void runWithRetries(String name, RetryableConfig retryableConfig, Runnable runnable) {
RetryConfig retryConfig = RetryConfig.custom()
.intervalFunction(IntervalFunction
.ofExponentialBackoff(retryableConfig.getInitialRetryIntervalMillis(), retryableConfig.getMultiplier()))
.maxAttempts(retryableConfig.getMaxRetries())
.build();
Retry.decorateRunnable(Retry.of(name, retryConfig), runnable).run();
}
}