Following an example in Google Sentiment Analysis Java API I have an application sending few hundred text samples for analysis to the service. Every now and then the API slows down significantly and when correlated with the timeline on the API Console, it is related to 500 and 504 errors.
Is there a recommended pattern to handle this kind of errors? I could not find a timeout parameter in the API, to be able to cancel the request say after 5 seconds and retry. Do I have to resort to wrapping the API call into a Future?
Here is the exact API I was looking for.
The documentation:
And a code snippet:
LanguageServiceClient createLanguage() throws IOException {
RetrySettings retrySettings = RetrySettings.newBuilder()
.setTotalTimeout(Duration.of(60, ChronoUnit.SECONDS))
.setMaxAttempts(2)
// Some other options
.build();
LanguageServiceSettings.Builder sb =
LanguageServiceSettings.newBuilder();
sb.annotateTextSettings().setRetrySettings(retrySettings);
return LanguageServiceClient.create(sb.build());
}