Retry on AmazonSQSClient

2k views Asked by At

I'm using AmazonSQSClient to interact with the SQS service and using the default client configuration which means it already is using the DEFAULT_RETRY_POLICY.

Let's say I make a call in my Java code to the "sendMessage" method.

As per the doc, the method can throw 2 types of Exceptions: InvalidMessageContentsException & UnsupportedOperationException.

Now let's say that the SQS service was unavailable due to whatever reason, and even after retries the SQSClient could not perform the sendMessage operation. I'm trying to understand how would I get to know that in my Java code. I can catch the aforementioned exceptions but I don't think these exceptions would have the info I need. They seem more related to an invalid message or an unsupported operation.

Am I missing something? Thoughts?

1

There are 1 answers

1
Taylor Wood On

This looks like the relevant Java SDK code.

    private void handleRetryableException(ExecOneRequestParams execOneParams, Exception e) {
        captureExceptionMetrics(e);
        awsRequestMetrics.addProperty(Field.AWSRequestID, null);
        SdkClientException sdkClientException;
        if (!(e instanceof SdkClientException)) {
            sdkClientException = new SdkClientException(
                    "Unable to execute HTTP request: " + e.getMessage(), e);
        } else {
            sdkClientException = (SdkClientException) e;
        }
        boolean willRetry = shouldRetry(execOneParams, sdkClientException);
        if (log.isTraceEnabled()) {
            log.trace(sdkClientException.getMessage() + (willRetry ? " Request will be retried." : ""), e);
        } else if (log.isDebugEnabled()) {
            log.trace(sdkClientException.getMessage() + (willRetry ? " Request will be retried." : ""));
        }
        if (!willRetry) {
            throw lastReset(sdkClientException);
        }
        // Cache the retryable exception
        execOneParams.retriedException = sdkClientException;
    }

This section leads me to believe you'll receive a SdkClientException with the causal exception inside of it.

        if (!(e instanceof SdkClientException)) {
            sdkClientException = new SdkClientException(
                    "Unable to execute HTTP request: " + e.getMessage(), e);