diff --git a/spring-cloud-aws-sqs/src/main/java/io/awspring/cloud/sqs/operations/SqsTemplate.java b/spring-cloud-aws-sqs/src/main/java/io/awspring/cloud/sqs/operations/SqsTemplate.java index 840d2960d..6f555f123 100644 --- a/spring-cloud-aws-sqs/src/main/java/io/awspring/cloud/sqs/operations/SqsTemplate.java +++ b/spring-cloud-aws-sqs/src/main/java/io/awspring/cloud/sqs/operations/SqsTemplate.java @@ -602,11 +602,11 @@ private ReceiveMessageRequest doCreateReceiveMessageRequest(Duration pollTimeout ReceiveMessageRequest.Builder builder = ReceiveMessageRequest.builder().queueUrl(attributes.getQueueUrl()) .maxNumberOfMessages(maxNumberOfMessages).messageAttributeNames(this.messageAttributeNames) .attributeNamesWithStrings(this.messageSystemAttributeNames) - .waitTimeSeconds(pollTimeout.toSeconds()); + .waitTimeSeconds(toInt(pollTimeout.toSeconds())); if (additionalHeaders.containsKey(SqsHeaders.SQS_VISIBILITY_TIMEOUT_HEADER)) { builder.visibilityTimeout( - getValueAs(additionalHeaders, SqsHeaders.SQS_VISIBILITY_TIMEOUT_HEADER, Duration.class) - .toSeconds()); + toInt(getValueAs(additionalHeaders, SqsHeaders.SQS_VISIBILITY_TIMEOUT_HEADER, Duration.class) + .toSeconds())); } if (additionalHeaders.containsKey(SqsHeaders.SQS_RECEIVE_REQUEST_ATTEMPT_ID_HEADER)) { builder.receiveRequestAttemptId( @@ -616,6 +616,15 @@ private ReceiveMessageRequest doCreateReceiveMessageRequest(Duration pollTimeout return builder.build(); } + // Convert a long value to an int. Values larger than Integer.MAX_VALUE are set to Integer.MAX_VALUE + private int toInt(long longValue) { + if (longValue > Integer.MAX_VALUE) { + return Integer.MAX_VALUE; + } + + return (int) longValue; + } + private V getValueAs(Map headers, String headerName, Class valueClass) { return valueClass.cast(headers.get(headerName)); }