Skip to content

Commit

Permalink
fix: Timeout settings in SqsTemplate
Browse files Browse the repository at this point in the history
* Timeouts were being set by calling Duration#getSecondsPart whic is
  alwawys a number between 0 and 59
* Update to use Duration#getSeconds to get the full timeout specified,
  in seconds
  • Loading branch information
joey committed Oct 2, 2024
1 parent 27eaa94 commit 4bd8bf7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.toSecondsPart());
.waitTimeSeconds(pollTimeout.toSeconds());
if (additionalHeaders.containsKey(SqsHeaders.SQS_VISIBILITY_TIMEOUT_HEADER)) {
builder.visibilityTimeout(
getValueAs(additionalHeaders, SqsHeaders.SQS_VISIBILITY_TIMEOUT_HEADER, Duration.class)
.toSecondsPart());
.toSeconds());
}
if (additionalHeaders.containsKey(SqsHeaders.SQS_RECEIVE_REQUEST_ATTEMPT_ID_HEADER)) {
builder.receiveRequestAttemptId(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ void shouldReceiveFromOptions() {
.willReturn(CompletableFuture.completedFuture(deleteResponse));
SqsOperations template = SqsTemplate.newSyncTemplate(mockClient);
Optional<Message<String>> receivedMessage = template.receive(from -> from.queue(queue)
.pollTimeout(Duration.ofSeconds(1)).visibilityTimeout(Duration.ofSeconds(5))
.pollTimeout(Duration.ofSeconds(61)).visibilityTimeout(Duration.ofSeconds(65))
.additionalHeader(headerName1, headerValue1).additionalHeaders(Map.of(headerName2, headerValue2)),
String.class);
assertThat(receivedMessage).isPresent().hasValueSatisfying(message -> {
Expand All @@ -949,8 +949,8 @@ void shouldReceiveFromOptions() {
then(mockClient).should().receiveMessage(captor.capture());
ReceiveMessageRequest request = captor.getValue();
assertThat(request.maxNumberOfMessages()).isEqualTo(1);
assertThat(request.visibilityTimeout()).isEqualTo(5);
assertThat(request.waitTimeSeconds()).isEqualTo(1);
assertThat(request.visibilityTimeout()).isEqualTo(65);
assertThat(request.waitTimeSeconds()).isEqualTo(61);
}

@Test
Expand Down

0 comments on commit 4bd8bf7

Please sign in to comment.