Micronaut supports retry mechanism for http clients if we use it in a declarative client like this :
@Client("http://127.0.0.1:8200")
@Retryable(delay = "${retry-delay}", attempts = "${retry-attempts}")
@Header(name = "username", value = "password")
public interface SampleHttpClient {
@Get(value = "/v1/kv/data/", produces = MediaType.APPLICATION_JSON)
HttpResponse<String> getVaultSecret();
}
Here retry-delay and retry-attempts are read from configuration yaml file.
But I am creating the http clients in my code on the fly as show below. This is because I get the http client parameters(URL, retry properties, header etc) at runtime.
How can I add retry option to my http configuration here ?
HttpClient client = null;
var configuration = new ServiceHttpClientConfiguration("myId", null,
null, new DefaultHttpClientConfiguration());
// how to add retry to http configuration here ???
client = new DefaultHttpClient("http://127.0.0.1:8200", configuration);
var uri = UriBuilder.of("http://127.0.0.1:8200").path("/v1/kv/data/").build();
var request = HttpRequest.GET(uri).header("username","password");
var response = client.toBlocking().exchange(request);