Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
remove AlreadyAcknowledgedException, return void instead of ChangeMes…
Browse files Browse the repository at this point in the history
…sageVisibilityResult
  • Loading branch information
Stephan.Praetsch committed Jun 13, 2024
1 parent 014209b commit adda920
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.model.ChangeMessageVisibilityRequest;
import com.amazonaws.services.sqs.model.ChangeMessageVisibilityResult;

import io.awspring.cloud.messaging.listener.Acknowledgment;

Expand Down Expand Up @@ -43,10 +42,10 @@ public synchronized void acknowledge() {
acknowledged.set(true);
}

public synchronized ChangeMessageVisibilityResult changeMessageVisibility(AmazonSQS sqsClient, ChangeMessageVisibilityRequest request) {
public synchronized void changeMessageVisibility(AmazonSQS sqsClient, ChangeMessageVisibilityRequest request) {
if (acknowledged.get()) {
throw new AlreadyAcknowledgedException();
return;
}
return sqsClient.changeMessageVisibility(request);
sqsClient.changeMessageVisibility(request);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* Copyright © 2017 Mercateo AG (http://www.mercateo.com)
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -18,10 +18,8 @@
import com.amazonaws.AmazonServiceException;
import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.model.ChangeMessageVisibilityRequest;
import com.amazonaws.services.sqs.model.ChangeMessageVisibilityResult;
import com.github.rholder.retry.Retryer;
import com.github.rholder.retry.RetryerBuilder;
import com.mercateo.sqs.utils.message.handling.AlreadyAcknowledgedException;
import com.mercateo.sqs.utils.message.handling.ErrorHandlingStrategy;
import com.mercateo.sqs.utils.message.handling.MessageWrapper;

Expand All @@ -42,7 +40,7 @@ public class VisibilityTimeoutExtender implements Runnable {

private final ErrorHandlingStrategy<?> errorHandlingStrategy;

private final Retryer<ChangeMessageVisibilityResult> retryer;
private final Retryer<Void> retryer;

VisibilityTimeoutExtender(@NonNull AmazonSQS sqsClient, @NonNull Duration newVisibilityTimeout,
@NonNull MessageWrapper<?> messageWrapper, @NonNull String queueUrl,
Expand All @@ -52,15 +50,15 @@ public class VisibilityTimeoutExtender implements Runnable {
this.messageWrapper = messageWrapper;
this.errorHandlingStrategy = errorHandlingStrategy;
this.retryer = RetryerBuilder
.<ChangeMessageVisibilityResult> newBuilder()
.<Void>newBuilder()
.retryIfException(t -> (t.getCause() instanceof UnknownHostException))
.withWaitStrategy(retryStrategy.getRetryWaitStrategy())
.withStopStrategy(retryStrategy.getRetryStopStrategy())
.build();

request = new ChangeMessageVisibilityRequest().withQueueUrl(queueUrl).withReceiptHandle(
messageWrapper.getReceiptHandle()).withVisibilityTimeout(
timeoutInSeconds(newVisibilityTimeout));
timeoutInSeconds(newVisibilityTimeout));
}

private Integer timeoutInSeconds(Duration timeout) {
Expand All @@ -70,11 +68,11 @@ private Integer timeoutInSeconds(Duration timeout) {
@Override
public void run() {
try {
retryer.call(() -> messageWrapper.changeMessageVisibility(sqsClient, request));
retryer.call(() -> {
messageWrapper.changeMessageVisibility(sqsClient, request);
return null;
});
} catch (Exception e) {
if (e.getCause() instanceof AlreadyAcknowledgedException) {
return;
}
if (e.getCause() instanceof AmazonServiceException) {
errorHandlingStrategy.handleExtendVisibilityTimeoutException((AmazonServiceException) e.getCause(), messageWrapper.getMessage());
} else {
Expand Down

0 comments on commit adda920

Please sign in to comment.